Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML and thread-safety
QtWS25 Last Chance

QML and thread-safety

Scheduled Pinned Locked Moved QML and Qt Quick
qmlqqmlapplicationthreadqtquick
5 Posts 4 Posters 4.3k Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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

    JKSHJ 1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      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
      0
      • B Offline
        B Offline
        Buttink
        wrote on last edited by
        #3

        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
        0
        • ? A Former User

          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

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          @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
          0
          • JKSHJ JKSH

            @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.

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @JKSH said:

            The QQmlApplicationEngine runs code in the thread which constructed it.

            Thank you very much!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved