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. Accessing application classes from a plugin?
Forum Updated to NodeBB v4.3 + New Features

Accessing application classes from a plugin?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 215 Views 1 Watching
  • 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 Offline
    A Offline
    Alhasni
    wrote on last edited by Alhasni
    #1

    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
    0
    • David_001D Offline
      David_001D Offline
      David_001
      wrote on last edited by David_001
      #2

      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
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved