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. Can I pass signals and slots as arguments?
QtWS25 Last Chance

Can I pass signals and slots as arguments?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 9.2k 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.
  • H Offline
    H Offline
    hcjiv1
    wrote on last edited by
    #1

    Here's what I would like to do. I am writing a plugin architecture where the plugins are able to generate QWidgets. Those QWidgets will have signals and slots based on some consistent naming convention so that the signals and slots can be matched up appropriately. For instance, maybe one of the widgets has a signal called highlightThingSignal and another widget has a slot called highlightThingSlot. What I need to do to make this work is call a method in the plugin that returns the widget, a list of its signals and a list of its slots. And then after matching them appropriately I need to be able to connect them. Is there a way to 'pass' signals and slots as arguments or maybe another better way to accomplish the same thing.

    TIA,
    -Harry

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      First of all, you can find out which signals and slots any object has by using QMetaObject. Qt 4.8 will introduce a connect() overload taking QMetaMethods.

      You can also just return a list of char* (or QByteArrays) containing their names, and do the connect yourself. Just remember to prepend a literal '1' or '2' to your signals/slots when you pass them to connect() (see the definition of the SIGNAL / SLOT macros).

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • R Offline
        R Offline
        renato.filho
        wrote on last edited by
        #3

        in Qt you can see some function which uses signal/slot as argument. Check: QMenu::addAction

        You can pass the macro SIGNAL/SLOT as arguments this will make the necessary adjustments to get the correct signature.

        @
        something like that: menu.addAction("text", recever, SLOT(myslot()));
        @

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hcjiv1
          wrote on last edited by
          #4

          At first glance at least it looks like QMetaObject along with your suggestion about the prepended "1" or "2" will work just fine! The beauty of the solution is that the plugin developer doesn't even need to pass the list of signals and slots. They just create them and it works. Being able to pass QMetaMethods to connect will be nice.

          Thanks!
          -Harry

          1 Reply Last reply
          0
          • B Offline
            B Offline
            billconan
            wrote on last edited by
            #5

            i my own program, i need to do a similar thing, but i instead pass the name of the slot function as the parameter in the form of QString.

            and i get the method's id with QMetaObject()->methodId("function name");

            and call the function with QMetaMethod()->invoke(...)

            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