[Allowed] Converting Qt 4.8 to 5 QPluginLoader-> instance returns null

I wrote an application using QT 4.8.2. It dynamically loads different plugins to provide multiple functionality to the user. Now Qt5 has been released and I wanted to convert my project to the newest version.

I have everything to work with except loading the plugin using QPluginLoader-> instance (). It worked fine when using Qt 4.8.2.

-> errorString says "The file ... /plugins/nlprod.dll is not a valid Qt plugin."

Here is my code:

PluginLoader.cpp:

//"fileName" contains the name of the .dll
pluginLoader->setFileName(pluginsDir->absoluteFilePath(fileName));

//"a" contains the correct path + name of the .dll
QString a = pluginLoader->fileName();      

//"plugin" is null and success "false"
QObject *plugin = pluginLoader->instance();
bool success = pluginLoader->isLoaded();

      

MyPlugin.h:

class NLPro : public QObject, IConnection
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "NLPro" FILE "nlpro.json") // <- New since I've ported to Qt 5
    Q_INTERFACES(IConnection)
...
}

      

MyPlugin.cpp: Ive removed the following:

Q_EXPORT_PLUGIN2(NLPro, NLPro);

      

and I've added a .json file with the following content:

{ "Keys": [ "NLPro"] }

      

Any idea?

Thanks in advance!

Hello

Fixed:

While

TARGET = $$qtLibraryTarget(nlpro)

      

worked correctly with Qt 4.8 I had to change it to

TARGET = $$qtLibraryTarget(nlpro)

      

for Qt 5.0

+3


source to share





All Articles