Unsolved Accessing application classes from a plugin?
-
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?
-
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();
-
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.