将Qt 4.8转换为5 QPluginLoader->;实例返回null
我使用Qt4.8.2编写了一个应用程序。它会动态加载不同的插件,为用户提供多种功能。 现在Qt5发布了,我想把我的项目转换成最新版本 除了用QPluginLoader->instance()加载插件外,我已经完成了所有工作。当使用Qt4.8.2时,它运行良好 ->错误字符串表示: “文件“…/plugins/nlprod.dll”不是有效的Qt插件。” 这是我的密码: PluginLoader.cpp:将Qt 4.8转换为5 QPluginLoader->;实例返回null,qt,qt5,Qt,Qt5,我使用Qt4.8.2编写了一个应用程序。它会动态加载不同的插件,为用户提供多种功能。 现在Qt5发布了,我想把我的项目转换成最新版本 除了用QPluginLoader->instance()加载插件外,我已经完成了所有工作。当使用Qt4.8.2时,它运行良好 ->错误字符串表示: “文件“…/plugins/nlprod.dll”不是有效的Qt插件。” 这是我的密码: PluginLoader.cpp: //"fileName" contains the name of the .dll plu
//"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)
...
}
我添加了一个.json文件,其中包含以下内容:
{ "Keys": [ "NLPro"] }
解决方案由OP
修正了它:
当
Qt4.8运行正常,我不得不将其更改为
TARGET = $$qtLibraryTarget(NLPro)
对于Qt5.0请记住,使用Qt4编译的插件与Qt5不兼容。它们依赖于版本。使用Qt5编译插件是您唯一的选择。
TARGET = $$qtLibraryTarget(nlpro)
TARGET = $$qtLibraryTarget(NLPro)