Is QPluginLoader::instance() calling the plugin's constructor?
-
Hi,
I want to experiment with an abstract
IFace
that will be inherited byPluginA
andPluginB
.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.
-
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.
-
Hi,
At the moment I have a
DriverFactory
withregisterPlugin(const QString& driverName, callback_t cb)
,IDriver* createDriver(QObject* parent)
etc. This class keeps it's data in astd::map<QString, callback_t>
.My plugins have a static function like
static IDriver* createInstance(QObject* parent)
;But it seems
QLibrary
needs to resolveextern "C"
functions who can't be static. Anyway, I will mark this as solved since the topic is no longer relevant. -
@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.