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. Invokable and pure virtual method(s)
Forum Updated to NodeBB v4.3 + New Features

Invokable and pure virtual method(s)

Scheduled Pinned Locked Moved Solved General and Desktop
invokablevirtualqobject
13 Posts 5 Posters 9.7k Views 3 Watching
  • 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.
  • raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #2

    base class is enough.
    Since in the end the meta object calls the method as you would do, thus the same rules apply ;)

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    kshegunovK 1 Reply Last reply
    0
    • raven-worxR raven-worx

      base class is enough.
      Since in the end the meta object calls the method as you would do, thus the same rules apply ;)

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #3

      @raven-worx
      Thanks for clarifying that, I suspected as much. What about the first part of the question? Will the moc be clever enough to recognize the Q_INVOKABLE macro without the Q_OBJECT meta-object information? I need only to schedule a queued call through the event loop, I won't need all the QObject's bells and whistles?

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • Hamed.MasafiH Offline
        Hamed.MasafiH Offline
        Hamed.Masafi
        wrote on last edited by
        #4

        No, base class MUST BE inherits from QObject and QObject MUST BE declared in first place of base classes. In this case you can put Q_OBJECT macro into the class.

        Remote object sharing (OO RPC)
        http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

        Advanced, Powerful and easy to use ORM for Qt5
        https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

        raven-worxR 1 Reply Last reply
        -1
        • Hamed.MasafiH Hamed.Masafi

          No, base class MUST BE inherits from QObject and QObject MUST BE declared in first place of base classes. In this case you can put Q_OBJECT macro into the class.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #5

          @Hamed.Masafi said:

          No, base class MUST BE inherits from QObject and QObject MUST BE declared in first place of base classes. In this case you can put Q_OBJECT macro into the class.

          that's simply not true!!
          For such cases there is the Q_GADGET macro.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          kshegunovK 1 Reply Last reply
          1
          • raven-worxR raven-worx

            @Hamed.Masafi said:

            No, base class MUST BE inherits from QObject and QObject MUST BE declared in first place of base classes. In this case you can put Q_OBJECT macro into the class.

            that's simply not true!!
            For such cases there is the Q_GADGET macro.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #6

            @raven-worx
            Superb, thank you! I didn't know about the Q_GADGET macro, it must be new in Qt5.

            Read and abide by the Qt Code of Conduct

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

              @kshegunov Nop, it's older than that ;) Q_GADGET dates back to Qt 4

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

              kshegunovK 1 Reply Last reply
              0
              • SGaistS SGaist

                @kshegunov Nop, it's older than that ;) Q_GADGET dates back to Qt 4

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #8

                @SGaist
                Huh, thanks for the clarification. It's possible, although I never knew. Always something new to see, always something new to learn, I guess ... :)

                Read and abide by the Qt Code of Conduct

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

                  There are lots of hidden gems to discover even after years of using Qt :)

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

                  kshegunovK 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    There are lots of hidden gems to discover even after years of using Qt :)

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #10

                    @SGaist
                    I second that!

                    Read and abide by the Qt Code of Conduct

                    kshegunovK 1 Reply Last reply
                    0
                    • kshegunovK kshegunov

                      @SGaist
                      I second that!

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by
                      #11

                      @raven-worx @SGaist
                      Hello again,
                      Is it possible to have queued invocation on a gadget object? I can't seem to find such a thing. I'm currently retrieving the method itself by:

                      QMetaObject & metaObject = AgDialPrivate::staticMetaObject;
                      QMetaMethod scheduleChildAdd = metaObject.method(metaObject.indexOfMethod("scheduleChildAdd"));
                      

                      however, it looks like QMetaMethod::invokeOnGadget doesn't accept Qt::ConnectionType. Should I try out Q_PRIVATE_SLOT instead?

                      Kind regards.

                      Read and abide by the Qt Code of Conduct

                      T 1 Reply Last reply
                      0
                      • kshegunovK kshegunov

                        @raven-worx @SGaist
                        Hello again,
                        Is it possible to have queued invocation on a gadget object? I can't seem to find such a thing. I'm currently retrieving the method itself by:

                        QMetaObject & metaObject = AgDialPrivate::staticMetaObject;
                        QMetaMethod scheduleChildAdd = metaObject.method(metaObject.indexOfMethod("scheduleChildAdd"));
                        

                        however, it looks like QMetaMethod::invokeOnGadget doesn't accept Qt::ConnectionType. Should I try out Q_PRIVATE_SLOT instead?

                        Kind regards.

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

                        @kshegunov
                        AFAIK gadgets doesn't support signal / slot therefore only a direct call is possible.

                        kshegunovK 1 Reply Last reply
                        0
                        • T ttuna

                          @kshegunov
                          AFAIK gadgets doesn't support signal / slot therefore only a direct call is possible.

                          kshegunovK Offline
                          kshegunovK Offline
                          kshegunov
                          Moderators
                          wrote on last edited by kshegunov
                          #13

                          @ttuna
                          Hello,
                          Thanks, I know that. I wanted to have a method of my private object to be queued for later execution, because the ChildAdded event that I'm handling in an event filter is propagated before the child object is fully constructed. It appears that the gadgets have no such capability so I've implemented the functionality as a private slot, and it works okay. For anyone that might be interested, here's how:

                          class AGUI_API AgDial : public QStackedWidget
                          {
                              Q_OBJECT
                              // ...
                          
                          private:
                              Q_PRIVATE_SLOT(d(), void scheduleChildAdd(QPointer<QObject>))
                          };
                          

                          With the corresponding invocation in the event filter:

                          bool AgDial::eventFilter(QObject * object, QEvent * event)
                          {
                              switch (event->type())
                              {
                              case QEvent::ChildAdded:
                                  QMetaObject::invokeMethod(this, "scheduleChildAdd", Qt::QueuedConnection, Q_ARG(QPointer<QObject>, QPointer<QObject>(reinterpret_cast<QChildEvent *>(event)->child())));
                                  break;
                                  // ...
                              }
                          }
                          

                          Kind regards.

                          Read and abide by the Qt Code of Conduct

                          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