Qt Forum

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

    Forum Updated on Feb 6th

    Unsolved Accessing application classes from a plugin?

    General and Desktop
    3
    3
    73
    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.
    • A
      Alhasni last edited by Alhasni

      I create a plugin that implements my application's plugin interface, as in the Echo Plugin Example.

      Now, how can I access classes (other than the plugin interface) that are declared and defined in the application? When I try to instantiate one of the application classes in the Plugin, I get an unresolved external symbol linker error, which is expected.

      Is there a way to do this without building a library out of my application that contains those classes, and then linking it dynamically in both the application and the plugin?

      1 Reply Last reply Reply Quote 0
      • David_001
        David_001 last edited by David_001

        Maybe you can add a CLASSNAME POINTER* into your Plugin-Interface (do not forget to add foreward declaration of the class => class CLASSNAME) and do somethink like that when you init your plugin:

        QPluginLoader loader(fileName);
        QObject *possiblePlugin = loader.instance();
        
        if (possiblePlugin)
        {
            PluginInterface *plugin = qobject_cast<PluginInterface*>(possiblePlugin);
            if (plugin)
            {
                qInfo() << "Loaded plugin: " << plugin->get(NAME);
        
                plugin->core = this->m_core;
                plugin->onInit(BASEINIT);
                m_pluginList.append(plugin);
            }
        }
        

        Now you can work and have access inside your plugin with the CLASSNAME you want. In my example "core". Be carefull maybe it should be const.

        Inside Plugin: core->whatEVER();

        1 Reply Last reply Reply Quote 1
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          Move all the classes that you want to be able to use in both your application and plugin in a shared library and link your plugins as well as your application against said library.

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