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
Forum Updated to NodeBB v4.3 + New Features

QML and thread-safety

Scheduled Pinned Locked Moved QML and Qt Quick
qmlqqmlapplicationthreadqtquick
5 Posts 4 Posters 4.4k Views 2 Watching
  • 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 9 Mar 2015, 17:18 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

    J 1 Reply Last reply 10 Mar 2015, 02:17
    0
    • M Offline
      M Offline
      mcosta
      wrote on 9 Mar 2015, 17:35 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 9 Mar 2015, 17:39 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
          9 Mar 2015, 17:18

          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

          J Offline
          J Offline
          JKSH
          Moderators
          wrote on 10 Mar 2015, 02:17 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 10 Mar 2015, 02:20
          0
          • J JKSH
            10 Mar 2015, 02:17

            @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 10 Mar 2015, 02:20 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

            3/5

            9 Mar 2015, 17:39

            • Login

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