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. Is QPluginLoader::instance() calling the plugin's constructor?
QtWS25 Last Chance

Is QPluginLoader::instance() calling the plugin's constructor?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 381 Views
  • 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.
  • Petross404_Petros SP Offline
    Petross404_Petros SP Offline
    Petross404_Petros S
    wrote on last edited by
    #1

    Hi,

    I want to experiment with an abstract IFace that will be inherited by PluginA and PluginB.

    Now, I know I am supposed to cast like this and test for nullptr:

    if( auto d = qobject_cast<IFace*>(loader->instance(); d != nullptr)
    {
        d->doSomething();
    }
    

    But how my plugin's ctor was called and the object allocated memory?

    I can register the plugins and provide an IFace* IFace::create() interface to call the ctor and use with the factory pattern.

    Is this the way to initialize (test loader->instance and use the factory pattern) the correct way?

    Thank you.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      If I understand your intents correctly, your plugin shall provide the factory method as interface and then you can build your objects with your actual inherited interface.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Petross404_Petros SP 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        If I understand your intents correctly, your plugin shall provide the factory method as interface and then you can build your objects with your actual inherited interface.

        Petross404_Petros SP Offline
        Petross404_Petros SP Offline
        Petross404_Petros S
        wrote on last edited by
        #3

        Hi,

        At the moment I have a DriverFactory with registerPlugin(const QString& driverName, callback_t cb), IDriver* createDriver(QObject* parent) etc. This class keeps it's data in a std::map<QString, callback_t>.

        My plugins have a static function like static IDriver* createInstance(QObject* parent);

        But it seems QLibrary needs to resolve extern "C" functions who can't be static. Anyway, I will mark this as solved since the topic is no longer relevant.

        Christian EhrlicherC 1 Reply Last reply
        0
        • Petross404_Petros SP Petross404_Petros S

          Hi,

          At the moment I have a DriverFactory with registerPlugin(const QString& driverName, callback_t cb), IDriver* createDriver(QObject* parent) etc. This class keeps it's data in a std::map<QString, callback_t>.

          My plugins have a static function like static IDriver* createInstance(QObject* parent);

          But it seems QLibrary needs to resolve extern "C" functions who can't be static. Anyway, I will mark this as solved since the topic is no longer relevant.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Petross404_Petros-S said in Is QPluginLoader::instance() calling the plugin's constructor?:

          who can't be static

          This would somehow contradict the 'static' keyword - a static function is only visible in the translation unit where it was defined.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1

          • Login

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