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. How to add Arguments to bool QMetaObject::invokeMethod(QObject *context, Functor function, FunctorReturnType *ret)
Forum Updated to NodeBB v4.3 + New Features

How to add Arguments to bool QMetaObject::invokeMethod(QObject *context, Functor function, FunctorReturnType *ret)

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

    bool QMetaObject::invokeMethod(QObject *context, Functor function, FunctorReturnType *ret) is an overloaded function.
    I don't want to use bool QMetaObject::invokeMethod(QObject *obj, const char member, ...)
    const char
    is not convenient when the function name is changed.

    JonBJ 1 Reply Last reply
    0
    • T Toocold

      bool QMetaObject::invokeMethod(QObject *context, Functor function, FunctorReturnType *ret) is an overloaded function.
      I don't want to use bool QMetaObject::invokeMethod(QObject *obj, const char member, ...)
      const char
      is not convenient when the function name is changed.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Toocold
      What is your question? There are a number of overloads for QMetaObject::invokeMethod accepting parameters for you to choose from. If you want to use one with a Functor function argument and pass parameters I think you have to use a lambda, e.g. https://forum.qt.io/topic/101182/qmetaobject-invokemethod-with-arguments.

      T 1 Reply Last reply
      1
      • JonBJ JonB

        @Toocold
        What is your question? There are a number of overloads for QMetaObject::invokeMethod accepting parameters for you to choose from. If you want to use one with a Functor function argument and pass parameters I think you have to use a lambda, e.g. https://forum.qt.io/topic/101182/qmetaobject-invokemethod-with-arguments.

        T Offline
        T Offline
        Toocold
        wrote on last edited by Christian Ehrlicher
        #3

        @JonB Thanks, it is my question.
        But I wonder if I use it like this:

        QMetaObject::invokeMethod(obj, [=]() { obj.exec() }, Qt::BlockingQueuedConnection);
        Souds like this:
        QMetaObject::invokeMethod(NULL, [=]() { obj.exec() }, Qt::BlockingQueuedConnection);
        

        Is it Right? And is it thread-safe?

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Toocold said in How to add Arguments to bool QMetaObject::invokeMethod(QObject *context, Functor function, FunctorReturnType *ret):

          Is it Right?

          no, the second one will also be executed even if obj is destroyed in the meantime, the first will will not even compile.

          And is it thread-safe?

          What exactly?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          T 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @Toocold said in How to add Arguments to bool QMetaObject::invokeMethod(QObject *context, Functor function, FunctorReturnType *ret):

            Is it Right?

            no, the second one will also be executed even if obj is destroyed in the meantime, the first will will not even compile.

            And is it thread-safe?

            What exactly?

            T Offline
            T Offline
            Toocold
            wrote on last edited by
            #5

            @Christian-Ehrlicher The obj is created in GUI Thread, and I call this QMetaObject::invokeMethod int the another thread.

            QMetaObject::invokeMethod(obj, [=]() { obj.exec() }, Qt::BlockingQueuedConnection);
            

            Will the lambda function be excuted in the GUI Thread?

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Toocold said in How to add Arguments to bool QMetaObject::invokeMethod(QObject *context, Functor function, FunctorReturnType *ret):

              Will the lambda function be excuted in the GUI Thread?

              First, your code still does not compile. Second it is executed in the thread where obj lives in since it's a QueuedConnection - it's all documented

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              T 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                @Toocold said in How to add Arguments to bool QMetaObject::invokeMethod(QObject *context, Functor function, FunctorReturnType *ret):

                Will the lambda function be excuted in the GUI Thread?

                First, your code still does not compile. Second it is executed in the thread where obj lives in since it's a QueuedConnection - it's all documented

                T Offline
                T Offline
                Toocold
                wrote on last edited by
                #7

                @Christian-Ehrlicher Thanks. It cleared up my confusion

                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