Access Qt plugin classes from other plugins



  • Hi, I am loading a few shared object plugins using QPluginLoader from some subdirs:

    myInterface.h
    myPluginLoader.h

    -pluginA/interfaceA.h
    -pluginA/implemA.h

    -pluginB/interfaceB.h
    -pluginB/implemB.h

    etc.

    How do I get my pluginB to use classes from pluginA? I have no problem loading the plugins and calling their interface functions from myPluginLoader.h

    In implemB.h, I have included ../pluginA/implemA.h and tried to initialize the implemA class, but I get "symbol lookup error" and "undefined symbol: _ZN6implemAC1ERKd"

    I figure this is probably because I am linking pluginA to the base (myInterface/myPluginLoader etc.) but not linking pluginA to pluginB (and thus getting name mangling). I tried to export implemA using Q_DECL_EXPORT as:

    class Q_DECL_EXPORT implemA
    { ... }
    

    and

    class Q_DECL_IMPORT implemB
    { ... }
    

    as described here: QT Doc Creating Shared Libraries
    but that gave me the same problem. Any idea how to resolve this?

    Thank you!


  • Lifetime Qt Champion

    Hi and welome to devnet,

    If you have several plugins using shared code then the most simple thing to do is move all the common code in a shared lib that you will link to all the plugins using them.



  • @SGaist Thanks for the response!

    I assume the plugins would link to the shared code in the usual way (-Lshared/path -lsharedlib)?

    Is having plugins with dependencies on one another generally considered bad practice?


  • Lifetime Qt Champion

    That assumption is corrected.

    AFAIK, having linking dependencies between two plugins is not a clean design.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.