Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    QML and thread-safety

    QML and Qt Quick
    qml qqmlapplication thread qtquick
    4
    5
    3457
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User last edited by

      Hi everyone,

      I'm writing an application with a QtQuick UI and the business logic in C++. My main window is instantiated by a QQmlApplicationEngine. I create some objects in C++ and pass them over to the QML engine as context properties. These objects are manipulated from both the QML side and the C++ side. My question is: Does the QQmlApplicationEngine run in its own thread and do I have to take care about thread-safety or does the whole application run in a single thread?

      Cheers!
      Wieland

      JKSH 1 Reply Last reply Reply Quote 0
      • M
        mcosta last edited by

        IMO there's no general answer to your question.
        Using signals/slots you can share information across objects in multi-thread as well as in a single thread application.

        The choice depends to your application requirements and constraints. Can you give more information?

        Once your problem is solved don't forget to:

        • Mark the thread as SOLVED using the Topic Tool menu
        • Vote up the answer(s) that helped you to solve the issue

        You can embed images using (http://imgur.com/) or (http://postimage.org/)

        1 Reply Last reply Reply Quote 0
        • B
          Buttink last edited by

          I currently have an application that has both QML and C++ and I have no problems with thread-safety. That being said, I do not make any WorkerScript items in QML nor do I make another thread in C++. So in my case if I debug and stop in one of my C++ classes the application doesnt respond to input like a mouse or keyboard. (just trying to make this clear lol)

          1 Reply Last reply Reply Quote 0
          • JKSH
            JKSH Moderators @Guest last edited by

            @Wieland said:

            Does the QQmlApplicationEngine run in its own thread and do I have to take care about thread-safety or does the whole application run in a single thread?

            The QQmlApplicationEngine runs code in the thread which constructed it. You don't have to worry about thread safety, unless you explicitly use WorkerScript in QML (or you spawn new threads in C++).

            If you use any GUI components (i.e. if you use Qt Quick items), then your QQmlApplicationEngine must be constructed in the GUI thread, so that it runs code in the GUI thread.

            The GUI thread is the thread which constructs QGuiApplication.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            ? 1 Reply Last reply Reply Quote 0
            • ?
              A Former User @JKSH last edited by

              @JKSH said:

              The QQmlApplicationEngine runs code in the thread which constructed it.

              Thank you very much!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post