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. Dynamc Call for QMetaObject::invokeMethod
Forum Updated to NodeBB v4.3 + New Features

Dynamc Call for QMetaObject::invokeMethod

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 1.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.
  • Christian EhrlicherC Christian Ehrlicher

    The documentation shows how to pass arguments to invokeMethod - or what do you want to achieve?

    T Offline
    T Offline
    ThenewQtDev
    wrote on last edited by
    #3

    @Christian-Ehrlicher i have tried it
    i have enum
    and for loop
    inside the for loop i want to call QMetaObject::invokeMethod with enum member as function
    with index of the loop a argument

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

      So did you actually read my link? There is an example on how to call invokeMethod with parameters:

      QString retVal;
      QMetaObject::invokeMethod(obj, "compute", Qt::DirectConnection,
                                Q_RETURN_ARG(QString, retVal),
                                Q_ARG(QString, "sqrt"),
                                Q_ARG(int, 42),
                                Q_ARG(double, 9.7));
      

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

      1 Reply Last reply
      2
      • T ThenewQtDev

        @Christian-Ehrlicher i have tried it
        i have enum
        and for loop
        inside the for loop i want to call QMetaObject::invokeMethod with enum member as function
        with index of the loop a argument

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #5

        @ThenewQtDev
        You said you tried,
        can you show is, us what you tried?


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        T 1 Reply Last reply
        3
        • J.HilkJ J.Hilk

          @ThenewQtDev
          You said you tried,
          can you show is, us what you tried?

          T Offline
          T Offline
          ThenewQtDev
          wrote on last edited by
          #6

          @J-Hilk for(int index = 0 ;index<MyFrame.length();index++)
          {

          int x;
          QMetaObject::invokeMethod(this, PresentState,Qt::DirectConnection,Q_RETURN_ARG(int, x),
          Q_ARG(int, index),
          Q_ARG(QByteArray, MyFrame));

          }

          J.HilkJ 1 Reply Last reply
          0
          • T ThenewQtDev

            @J-Hilk for(int index = 0 ;index<MyFrame.length();index++)
            {

            int x;
            QMetaObject::invokeMethod(this, PresentState,Qt::DirectConnection,Q_RETURN_ARG(int, x),
            Q_ARG(int, index),
            Q_ARG(QByteArray, MyFrame));

            }

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #7

            @ThenewQtDev said in Dynamc Call for QMetaObject::invokeMethod:

            PresentState

            Is incorrect it‘s supposed to be a string or a functionpointer


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            T 1 Reply Last reply
            1
            • J.HilkJ J.Hilk

              @ThenewQtDev said in Dynamc Call for QMetaObject::invokeMethod:

              PresentState

              Is incorrect it‘s supposed to be a string or a functionpointer

              T Offline
              T Offline
              ThenewQtDev
              wrote on last edited by
              #8

              @J-Hilk it is a Qstring

              J.HilkJ 1 Reply Last reply
              0
              • T ThenewQtDev

                @J-Hilk it is a Qstring

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #9

                @ThenewQtDev
                Than I‘m afraid you have to share a bit more code 😉


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                T 1 Reply Last reply
                0
                • J.HilkJ J.Hilk

                  @ThenewQtDev
                  Than I‘m afraid you have to share a bit more code 😉

                  T Offline
                  T Offline
                  ThenewQtDev
                  wrote on last edited by
                  #10

                  @J-Hilk i have problem when i put the name of the methode as " compute " t works
                  but when i put it as variable as mymthode it doent work

                  J.HilkJ 1 Reply Last reply
                  0
                  • T ThenewQtDev

                    @J-Hilk i have problem when i put the name of the methode as " compute " t works
                    but when i put it as variable as mymthode it doent work

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #11

                    @ThenewQtDev
                    Well that‘s not unexpexted
                    it‘s expecting a char * not a QString.
                    Change your variable accordingly and it should work


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    T 1 Reply Last reply
                    4
                    • J.HilkJ J.Hilk

                      @ThenewQtDev
                      Well that‘s not unexpexted
                      it‘s expecting a char * not a QString.
                      Change your variable accordingly and it should work

                      T Offline
                      T Offline
                      ThenewQtDev
                      wrote on last edited by
                      #12

                      @J-Hilk wow thank you it works fine :)

                      1 Reply Last reply
                      1

                      • Login

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