QML: Receive signals from C++ object in different thread



  • HI Everyone

    I hope I'm phrasing this correct.

    I want to send a signal from a C++ object running in a different thread than main.cpp, to a QML window. Currently I use the main.qml, which receives the signal and passes it to the QML window that needs to do some stuff when the signal is emitted. This does'nt feel right.

    Is there a pattern to do this? I guess binding the object to QML, even though its running in a different thread.

    Thanks for the help.



  • Could you post any example?

    Is the QML Window declared in the main.qml?
    Does main.qml receive the signal?



  • its gonna be a lot of code to post.

    but, the way it works now is: the qml window's (window2,qml) parent is declared in main.qml (window1.qml). I then have a mainThread.cpp that connects to main.qml, so, any object running (e.g. test.cpp) in a different thread emits a signal to mainThread.cpp, and this signal is received by main.qml, then main.qml calls a function (decalred in window1.qml) to access the child window (window2.qml) and to process the signal emitted by test.cpp).

    so, i have main.qml, that receives any signals and passes it to the relevant window. thats what i'm not happy with. If there is a pattern to access the signal (emitted from test.cpp) directly to window2.qml, bypassing main.qml, I'd be very happy. but Window2.qml cannot receive signals directly from test.cpp.

    From what I could tell, I'd probably have to add something like this into the test.cpp object:

    QmlApplicationViewer viewer;
    viewer.setMainQmlFile(QLatinString("qml/project_folder/Window2.qml");
    viewer.showExpanded();

    but I want to confirm that I'm on the right track, if not, can you do it, and how do you do it.

    Thanks!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.