Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [SOLVED] QMetaObject::invokeMethod with boost::shared_ptr argument
Forum Update on Monday, May 27th 2025

[SOLVED] QMetaObject::invokeMethod with boost::shared_ptr argument

Scheduled Pinned Locked Moved C++ Gurus
6 Posts 2 Posters 2.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.
  • A Offline
    A Offline
    ASxa86
    wrote on 27 Mar 2014, 02:59 last edited by
    #1

    @
    Q_DECLARE_METATYPE(boost::shared_ptrMy::Class)

    void function()
    {
    auto val = QMetaObject::invokeMethod(this->m_object->sender, "senderFunction", Qt::AutoConnection, Q_ARG(boost::shared_ptrMy::Class, this->m_myClass));
    }
    @

    When running my app, Qt reports "No such method"

    Am I doing something wrong here?

    senderFunction() is an inherited function which sender has public access to from the base class. Is this causing the problem?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ASxa86
      wrote on 27 Mar 2014, 04:12 last edited by
      #2

      Answering my own question. It appears that for a function to be called by invokeMethod, the function must be declared as a slot.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 27 Mar 2014, 07:39 last edited by
        #3

        Hi,

        Unless you really want your function to be a a slot, there's also the Q_INVOKABLE keyword, the end effect is the same but it makes your code clearer.

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ASxa86
          wrote on 27 Mar 2014, 14:04 last edited by
          #4

          Oh thanks, I'll give it a shot. That would actually be much better.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ASxa86
            wrote on 27 Mar 2014, 14:42 last edited by
            #5

            So while Q_INVOKABLE will work, it does not solve my main issue. Many of my widgets inherit from a non-qt base class. This class is capable of setting a pointer to my kernel.

            @
            class WidgetBase
            {
            public:
            void setKernel(Kernel* x);
            };
            @

            So in effect, all of my widgets are able to set the kernel. The problem is I need to be able to set these kernels on a separate thread from the widgets I have created.

            As far as I can tell, WidgetBase would have to inherit from Q_Object so that I could set "setKernel" as Q_INVOKABLE. Now WidgetBase inherits from Q_Object and I can no longer inherit from WidgetBase with any of my custom widgets. This is also true declaring as slots.

            @
            class WidgetBase : public Q_Object
            {
            Q_OBJECT
            public:
            Q_INVOKABLE void setKernel(Kernel* x);
            };
            @

            Is my only option to not inherit from WidgetBase and have every custom widget i've created so far run their own setKernel() function?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 27 Mar 2014, 21:14 last edited by
              #6

              Not their own. But you would need first to make it virtual and for the widgets that uses it, you need to reimplement it (adding the Q_INVOKABLE keyword in the declaration) and just call the base class implementation.

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

              1 Reply Last reply
              0

              1/6

              27 Mar 2014, 02:59

              • Login

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