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. Calls from QML to context property objects only in main thread?
Forum Updated to NodeBB v4.3 + New Features

Calls from QML to context property objects only in main thread?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 744 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    Is there some kind of guarantee that all calls from QML to context property object's Q_PROPERTY and Q_INVOKABLE entry points only happen in the main (GUI) thread?

    I was looking for documentation on this, but didn't find any.

    Question is: Do I need to implement my functions reentrant or thread-safe?

    KroMignonK 1 Reply Last reply
    0
    • A Asperamanca

      Is there some kind of guarantee that all calls from QML to context property object's Q_PROPERTY and Q_INVOKABLE entry points only happen in the main (GUI) thread?

      I was looking for documentation on this, but didn't find any.

      Question is: Do I need to implement my functions reentrant or thread-safe?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by KroMignon
      #2

      @Asperamanca said in Calls from QML to context property objects only in main thread?:

      Is there some kind of guarantee that all calls from QML to context property object's Q_PROPERTY and Q_INVOKABLE entry points only happen in the main (GUI) thread?

      I don't think so.
      Depending on backend used, it is possible that QML rendering uses multiple threads (cf. https://doc.qt.io/qt-5/qtquick-visualcanvas-scenegraph.html), so I suppose this will also be possible for calls from QML.

      If you are calling directly a function from QML (Q_INVOKABLE or slot) you should ensure it is thread safe, but Q_PROPERTY() should not be a problem, those will be called from event loop and therefore should be in the right thread.

      EDIT: after reading documentation, I change my mind ;)

      QML is executed by QQmlContext (https://doc.qt.io/qt-5/qqmlcontext.html), which runs in the thread in which it has been created, so if you create your QML context in main thread and also the C++ classes, it should not be required.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      A 1 Reply Last reply
      0
      • KroMignonK KroMignon

        @Asperamanca said in Calls from QML to context property objects only in main thread?:

        Is there some kind of guarantee that all calls from QML to context property object's Q_PROPERTY and Q_INVOKABLE entry points only happen in the main (GUI) thread?

        I don't think so.
        Depending on backend used, it is possible that QML rendering uses multiple threads (cf. https://doc.qt.io/qt-5/qtquick-visualcanvas-scenegraph.html), so I suppose this will also be possible for calls from QML.

        If you are calling directly a function from QML (Q_INVOKABLE or slot) you should ensure it is thread safe, but Q_PROPERTY() should not be a problem, those will be called from event loop and therefore should be in the right thread.

        EDIT: after reading documentation, I change my mind ;)

        QML is executed by QQmlContext (https://doc.qt.io/qt-5/qqmlcontext.html), which runs in the thread in which it has been created, so if you create your QML context in main thread and also the C++ classes, it should not be required.

        A Offline
        A Offline
        Asperamanca
        wrote on last edited by Asperamanca
        #3

        @KroMignon
        Thank you. I thought pretty much the same...while the rendering can happen in multiple threads, the data acquisition should be in one thread only.

        EDIT: And for QQuickImageProviders they explicitly say you need to be able to handle calls from different threads.

        KroMignonK 1 Reply Last reply
        0
        • A Asperamanca

          @KroMignon
          Thank you. I thought pretty much the same...while the rendering can happen in multiple threads, the data acquisition should be in one thread only.

          EDIT: And for QQuickImageProviders they explicitly say you need to be able to handle calls from different threads.

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #4

          @Asperamanca said in Calls from QML to context property objects only in main thread?:

          EDIT: And for QQuickImageProviders they explicitly say you need to be able to handle calls from different threads.

          Yes, this is normal because renderer could be multiple-threaded.

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          A 1 Reply Last reply
          0
          • KroMignonK KroMignon

            @Asperamanca said in Calls from QML to context property objects only in main thread?:

            EDIT: And for QQuickImageProviders they explicitly say you need to be able to handle calls from different threads.

            Yes, this is normal because renderer could be multiple-threaded.

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            @KroMignon said in Calls from QML to context property objects only in main thread?:

            @Asperamanca said in Calls from QML to context property objects only in main thread?:

            EDIT: And for QQuickImageProviders they explicitly say you need to be able to handle calls from different threads.

            Yes, this is normal because renderer could be multiple-threaded.

            My conclusion here is that they would note it elsewhere, if calls from multiple threads are to be expected.

            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