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?
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 388 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.
  • P Offline
    P Offline
    Petross404_Petros S
    wrote on 6 Apr 2022, 14:25 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 Apr 2022, 19:08 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

      P 1 Reply Last reply 8 Apr 2022, 11:38
      0
      • S SGaist
        6 Apr 2022, 19:08

        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.

        P Offline
        P Offline
        Petross404_Petros S
        wrote on 8 Apr 2022, 11:38 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.

        C 1 Reply Last reply 8 Apr 2022, 11:45
        0
        • P Petross404_Petros S
          8 Apr 2022, 11:38

          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.

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 8 Apr 2022, 11:45 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

          1/4

          6 Apr 2022, 14:25

          • Login

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