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.
  • J jsulm
    9 Mar 2020, 08:46

    @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 9 Mar 2020, 08:54 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.

    J 1 Reply Last reply 9 Mar 2020, 08:55
    0
    • S SJoshi
      9 Mar 2020, 08:54

      @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.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 9 Mar 2020, 08:55 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 9 Mar 2020, 09:07
      0
      • J jsulm
        9 Mar 2020, 08:55

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

        S Offline
        S Offline
        SJoshi
        wrote on 9 Mar 2020, 09:07 last edited by SJoshi 3 Sept 2020, 09:09
        #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 V 3 Replies Last reply 9 Mar 2020, 10:07
        0
        • S SJoshi
          9 Mar 2020, 09:07

          @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 9 Mar 2020, 10:07 last edited by
          #8
          This post is deleted!
          1 Reply Last reply
          0
          • S SJoshi
            9 Mar 2020, 09:07

            @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 9 Mar 2020, 10:08 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 9 Mar 2020, 10:16
            0
            • A Asperamanca
              9 Mar 2020, 10:08

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

              S Offline
              S Offline
              SJoshi
              wrote on 9 Mar 2020, 10:16 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
                9 Mar 2020, 09:07

                @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.

                V Offline
                V Offline
                VRonin
                wrote on 9 Mar 2020, 11:10 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 11 Mar 2020, 05:50
                2
                • V VRonin
                  9 Mar 2020, 11:10

                  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 11 Mar 2020, 05:50 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
                  • C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 11 Mar 2020, 05:55 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 11 Mar 2020, 06:07
                    2
                    • C Christian Ehrlicher
                      11 Mar 2020, 05:55

                      @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 11 Mar 2020, 06:07 last edited by
                      #14

                      @Christian-Ehrlicher Thank You!

                      1 Reply Last reply
                      0

                      14/14

                      11 Mar 2020, 06:07

                      • Login

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