[SOLVED] QPluginLoader unable to load a Qt Plugin
-
Hello all,
I have an Interface as shown below.
class MyInterface { public: virtual ~MyInterface() {} virtual int initialize() = 0; }; Q_DECLARE_INTERFACE(MyInterface, "com.example.MyInterface/1.0")
My plugin implements this interface and declares it in its class as shown below.
class QT_DECL_EXPORT MyPlugin : public QObject, public MyInterface { Q_OBJECT Q_INTERFACES(MyInterface) public: MyPlugin(); virtual ~MyPlugin(); public: int initialize(); // ... };
My plugin's project file sets the target appropriately.
TARGET = $$qtLibraryTarget(MyPlugin) TEMPLATE = lib
Now, all the modules (including my app) gets compiled. In the app where I have to load the plugin, I have the following code:
// ... QPluginLoader loader("MyPluginld.dll"); if (! loader.load()) qDebug() << "Error!"; MyInterface *base = qobject_cast<MyInterface *>(loader.instance()); if (base == NULL) qDebug() << "Error!"; // ...
The
loader.load()
function always fails. Am I making a mistake by providing incorrect name to theQPluginLoader
constructor? Or is something else wrong?Any help would be much appreciated.
Cheers!
Bharath -
In your code you expect that the DLL is in the same directory of the executable.
Is that TRUE??@mcosta Yes, that is correct. My deployment model ensures that both land up in the same directory.
Cheers!
ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
Bharath Narayan M G -
Hi,
if your DLL is in the right place you can use
QPluginLoader::errorString()
to understand whyload
fails@mcosta Thanks for that. I will see what the error string says.
-
Hi,
if your DLL is in the right place you can use
QPluginLoader::errorString()
to understand whyload
fails@mcosta
The errorString prints the following:"Plugin verification data mismatch in './/MyPluginld.dll'"
-
@bharath144 said:
Plugin verification data mismatch in
Had a quick look to Qt sources.
Seems that you must use this macro to define plugin's metadata.Reading here, the point 3. of "Writing a plugin involves these steps:" says the same thing
@mcosta That did the trick. I saw the step but I overlooked it thinking it may not be mandatory.
Thanks for the help.