Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Q_INVOKABLE vs SIGNAL/SLOT thread safety

Q_INVOKABLE vs SIGNAL/SLOT thread safety

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 3.4k 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.
  • D Offline
    D Offline
    DRoscoe
    wrote on last edited by
    #1

    I have several methods which are defined as Q_INVOKABLE. One such method is:

    Q_INVOKABLE void logError(const QString& msg_in);
    

    This method is called by my QML objects to log error events as suggested above.

    The class which defines this method is MainApp. It is running on my QGuiApplication event loop. MainApp also makes calls logError() to log its own error messages. I am trying to determine if the QML calls and my MainApp calls are thread safe, even though I am not explicitly defining a signal/slot connection

    Thanks!

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      If you call a Q_INVOKABLE method from QML it is called using QMetaObject::invokeMethod behind the scenes. So, it is thread-safe per se. But: Your usual QtQuick stuff lives on the GUI thread and thus, unless you explicitly use other threads, there's no problem anyways.

      Edit: My original answer was wrong.

      D 1 Reply Last reply
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        How are you calling that method ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          How are you calling that method ?

          D Offline
          D Offline
          DRoscoe
          wrote on last edited by
          #4

          @SGaist from my QML, I am calling:

          main_app.logError()
          

          Where main_app is the instance of my application.

          From the C++ side of the application, I am calling:

          logError()
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What @Wieland wrote is correct :)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • ? A Former User

              If you call a Q_INVOKABLE method from QML it is called using QMetaObject::invokeMethod behind the scenes. So, it is thread-safe per se. But: Your usual QtQuick stuff lives on the GUI thread and thus, unless you explicitly use other threads, there's no problem anyways.

              Edit: My original answer was wrong.

              D Offline
              D Offline
              DRoscoe
              wrote on last edited by
              #6

              @Wieland Thanks!

              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