Qt and Unity Texture Sharing

42 Views Asked by At

I have two applications: a Unity app and a Qt app. I need to include the Unity app content as an item in my Qt application.

What are the best way for doing so? Could we have some form of communication between the two via RTSP or UDP? Is there even a way to send the texture through UDP socket in Unity? Both applications will operate on the same machine. I tried to embed the unity app inside the qt app using the following code :

 WId id = (WId)FindWindow(NULL, L"unityApp");
    if (!id)
        return -1;

    QApplication a(argc, argv);
    QWindow* window = QWindow::fromWinId(id);
    window->requestActivate();
    QWidget* widget = QWidget::createWindowContainer(window);
    widget->setGeometry(0,0, 9300, 720);
    widget->show();

but this solution uses qt widgets and i need it to be in the qml. I found another solution that i can get the textureId from unity and show it in my qt app but i have no idea if this is possible.

I'm using Qt6.5.3 on Windows.

1

There are 1 best solutions below

0
Anh Nguyen Ngoc On BEST ANSWER

You can try:

  1. Subwindow Integration: Think of it like fitting a picture into a frame. You can take the Unity app's window and snugly fit it inside your Qt application's interface. This involves a bit of behind-the-scenes work with Windows' own toolkit to get the Unity window's handle (its unique identifier) and then telling Qt, "Hey, let's treat this as part of our layout." It's a neat trick that blends both apps visually.
  2. Texture Sharing: Unity is painting on a canvas, and you want to show that artwork live in your Qt gallery. By sharing textures between Unity and Qt, you essentially allow Unity to render its graphics directly onto a surface that Qt can display. This method talks GPU language, using OpenGL or Direct3D, and while it demands a deeper dive into graphics programming, the result is seamless and smooth.

Hope this will help you. Thank you.