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 pass custom class reference to QMetaObject::invokeMethod

How to pass custom class reference to QMetaObject::invokeMethod

Scheduled Pinned Locked Moved Solved General and Desktop
qmetaobject
14 Posts 5 Posters 2.8k 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.
  • S SJoshi

    Hey folks, I hope you all are doing well.

    I stuck in a scenario on which I have created a class reference but not able to handle it properly and getting errors like No such method of such type, unregistered data type, etc..

    Can you help me get over this issue as I am sharing the code scenario :

    I am having a class ABC for which I have created its reference here :

    ABC* child;
    

    As I am calling this function from some another class :

    QMetaObject::invokeMethod(this, "demo", Qt::QueuedConnection, Q_ARG(ABC*, obj), Q_ARG(bool, true))
    

    Method :

    void demo(ABC* ref, bool var) {
    ...}
    
    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @SJoshi said in How to pass custom class reference to QMetaObject::invokeMethod:

    for which I have created its reference here

    You created a pointer, not reference.

    Where is this demo() method actually defined?
    Because you have to pass pointer to class instance to invokeMethod() where demo() is defined.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    S 1 Reply Last reply
    2
    • jsulmJ jsulm

      @SJoshi said in How to pass custom class reference to QMetaObject::invokeMethod:

      for which I have created its reference here

      You created a pointer, not reference.

      Where is this demo() method actually defined?
      Because you have to pass pointer to class instance to invokeMethod() where demo() is defined.

      S Offline
      S Offline
      SJoshi
      wrote on last edited by
      #5

      @jsulm Hi I am sorry that I used reference word, actually, demo() is on some another class I didn't mention it on here and it's a public slot too. Also, I have passed the actual object of the class where the demo is put instead of this. But I don't know where I am doing the mistake.

      jsulmJ 1 Reply Last reply
      0
      • S SJoshi

        @jsulm Hi I am sorry that I used reference word, actually, demo() is on some another class I didn't mention it on here and it's a public slot too. Also, I have passed the actual object of the class where the demo is put instead of this. But I don't know where I am doing the mistake.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @SJoshi Please post code you're really using and show how you registered ABC.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        S 1 Reply Last reply
        0
        • jsulmJ jsulm

          @SJoshi Please post code you're really using and show how you registered ABC.

          S Offline
          S Offline
          SJoshi
          wrote on last edited by SJoshi
          #7

          @jsulm Sure actually it's a bit complex code so I am just sharing the main logic with you :

          Q_DECLARE_METATYPE(ABC*)
          
          void MainWindow::senData() {
          
          ABC* temp;
          
          some logic applied on temp
          
          QMetaObject::invokeMethod(pv, "demo", Qt::QueuedConnection, Q_ARG(ABC*, temp), Q_ARG(bool, false))
          
          ...
          
          }
          

          In the above logic PV is an object pageView class and created as: pageView* pv = new PageView().

          void pageView::demo(ABC* obj, bool handle) {
          
          ...
          
          }
          

          Error : QMetaMethod::invoke: Unable to handle unregistered datatype 'ABC*

          Please let me know If I am missing something.

          A VRoninV 3 Replies Last reply
          0
          • S SJoshi

            @jsulm Sure actually it's a bit complex code so I am just sharing the main logic with you :

            Q_DECLARE_METATYPE(ABC*)
            
            void MainWindow::senData() {
            
            ABC* temp;
            
            some logic applied on temp
            
            QMetaObject::invokeMethod(pv, "demo", Qt::QueuedConnection, Q_ARG(ABC*, temp), Q_ARG(bool, false))
            
            ...
            
            }
            

            In the above logic PV is an object pageView class and created as: pageView* pv = new PageView().

            void pageView::demo(ABC* obj, bool handle) {
            
            ...
            
            }
            

            Error : QMetaMethod::invoke: Unable to handle unregistered datatype 'ABC*

            Please let me know If I am missing something.

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #8
            This post is deleted!
            1 Reply Last reply
            0
            • S SJoshi

              @jsulm Sure actually it's a bit complex code so I am just sharing the main logic with you :

              Q_DECLARE_METATYPE(ABC*)
              
              void MainWindow::senData() {
              
              ABC* temp;
              
              some logic applied on temp
              
              QMetaObject::invokeMethod(pv, "demo", Qt::QueuedConnection, Q_ARG(ABC*, temp), Q_ARG(bool, false))
              
              ...
              
              }
              

              In the above logic PV is an object pageView class and created as: pageView* pv = new PageView().

              void pageView::demo(ABC* obj, bool handle) {
              
              ...
              
              }
              

              Error : QMetaMethod::invoke: Unable to handle unregistered datatype 'ABC*

              Please let me know If I am missing something.

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

              @SJoshi Can you add the include statements prior to Q_DECLARE_METATYPE?
              Also, do you use namespaces?

              S 1 Reply Last reply
              0
              • A Asperamanca

                @SJoshi Can you add the include statements prior to Q_DECLARE_METATYPE?
                Also, do you use namespaces?

                S Offline
                S Offline
                SJoshi
                wrote on last edited by
                #10

                @Asperamanca Yes I declared Q_DECLARE_METATYPE just after the include statements and I'm not using any namespaces.

                1 Reply Last reply
                0
                • S SJoshi

                  @jsulm Sure actually it's a bit complex code so I am just sharing the main logic with you :

                  Q_DECLARE_METATYPE(ABC*)
                  
                  void MainWindow::senData() {
                  
                  ABC* temp;
                  
                  some logic applied on temp
                  
                  QMetaObject::invokeMethod(pv, "demo", Qt::QueuedConnection, Q_ARG(ABC*, temp), Q_ARG(bool, false))
                  
                  ...
                  
                  }
                  

                  In the above logic PV is an object pageView class and created as: pageView* pv = new PageView().

                  void pageView::demo(ABC* obj, bool handle) {
                  
                  ...
                  
                  }
                  

                  Error : QMetaMethod::invoke: Unable to handle unregistered datatype 'ABC*

                  Please let me know If I am missing something.

                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #11

                  You already have the answer at hand

                  @SJoshi said in How to pass custom class reference to QMetaObject::invokeMethod:

                  Unable to handle unregistered datatype 'ABC*

                  @Asperamanca said in How to pass custom class reference to QMetaObject::invokeMethod:

                  You need to register the class using [...] qRegisterMetaType()

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  S 1 Reply Last reply
                  2
                  • VRoninV VRonin

                    You already have the answer at hand

                    @SJoshi said in How to pass custom class reference to QMetaObject::invokeMethod:

                    Unable to handle unregistered datatype 'ABC*

                    @Asperamanca said in How to pass custom class reference to QMetaObject::invokeMethod:

                    You need to register the class using [...] qRegisterMetaType()

                    S Offline
                    S Offline
                    SJoshi
                    wrote on last edited by
                    #12

                    @VRonin Thanks It worked for me but I have a small doubt what's a suitable place to use qRegisterMetaType. For now, I have used it on the very first line of MainWindow::senData() method.

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

                      @SJoshi said in How to pass custom class reference to QMetaObject::invokeMethod:

                      For now, I have used it on the very first line of MainWindow::senData() method.

                      There is no need to re-register it every time. The ctor of this class is fine.

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

                      S 1 Reply Last reply
                      2
                      • Christian EhrlicherC Christian Ehrlicher

                        @SJoshi said in How to pass custom class reference to QMetaObject::invokeMethod:

                        For now, I have used it on the very first line of MainWindow::senData() method.

                        There is no need to re-register it every time. The ctor of this class is fine.

                        S Offline
                        S Offline
                        SJoshi
                        wrote on last edited by
                        #14

                        @Christian-Ehrlicher Thank You!

                        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