Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    General and Desktop
    2
    2
    546
    Loading More Posts
    • 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
      primem0ver last edited by

      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 Reply Quote 0
      • G
        giesbert last edited by

        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 Reply Quote 0
        • First post
          Last post