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 (dynamically) call an arbitrary plugin class function from another class?
QtWS25 Last Chance

Can I (dynamically) call an arbitrary plugin class function from another class?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 699 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.
  • P Offline
    P Offline
    primem0ver
    wrote on last edited by
    #1

    My goal (if it is possible)... is to create a widget that inherits QToolButton and is assigned a callback function from a plugin. I know that it is possible to create a function pointer within the Button class but the problem is that from what I have read about function pointers, the class type is part of the declaration. For example:

    @MyReturnType (MyClass::* functionPointer)(ParameterType1 parameter1, ParameterType2 parameter2,...)@

    As I understand it, In the above example, the type MyClass must be known ahead of time but since this is a plugin, that knowledge is not possible. Since the plugin interface is the only thing known a priori (ahead of time) and a plugin will have an arbitrary class name and since it can have (and will have) any number of unique functions that need to be called when a button is pressed, it is impossible to know what MyClass is ahead of time.

    So is doing such a thing possible? I was thinking that the signal slot features of Qt might be a solution. Theoretically I could have a signal that uses a function pointer as a parameter for the signal and is passed to the slot. The slot would exist in the target plugin and the target plugin could then call the function that needs to be called from the slot. But... I might run into the same problem as above if the syntax for such a feat would again require that MyClass be known ahead of time.

    Ultimately this Button type I am proposing is to be used in a universal toolbar type because each of these plugins must provide a toolbar that is used to give the user access to the functionality of the plugin.

    Perhaps there is a simpler solution?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi,
      what you can do is use the SIGNAL/SLOT mechanism for that. If the plugin is a QObject derived class, you can call functions there by "QMetaObject::invokeMethod":http://qt-project.org/doc/qt-5/qmetaobject.html#invokeMethod

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      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