Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Can QML Viwer be run on a seperate Thread?



  • As I try and wrap my head around QML and how to use it in my cpp application I had a few questions. In my particular situation I am trying to use QML to build the interface for a plugin that I have developed for another application (Maya). I ran a test using:
    @QDeclarativeView view;
    view.setSource(QUrl("qrc:/myCustomUI.qml"));
    view.show();@
    This resulted in my allowing me to my UI for the duration of time that my function ran. However, as you can imagine this was not my desired result. So I guess my questions are what the best approach would be run a QML interface in a plugin for another application and am I right in thinking that I would have to run the UI on a separate thread from my main application. Anyway I just thought I would ask here first before I dig in to deep, hoping that someone might be able to provide some direction on how to pull this off.



  • To answer part of my own question I some how missed using the "app.exec()" at the end of my function. Now it remains on the screen.

    @QDeclarativeView view;
    view.setSource(QUrl("qrc:/myCustomUI.qml"));
    view.show();
    return app.exec();
    @

    Still looking in the multi-threading aspect. Will post what I discover.



  • QDeclarativeView, as every other GUI class, must live in the main thread. There is no way to circumvent this and move it to another thread.


Log in to reply