我使用QT 4.8.2编写了一个应用程序。它会动态加载不同的插件,为用户提供多种功能。 现在Qt5发布了,我想将我的项目转换为最新版本。
除了用QPluginLoader-> instance()加载插件外,我得到了一切。使用Qt 4.8.2时,它运行良好。
- > errorString说: “文件'... / plugins / nlprod.dll'不是有效的Qt插件。”
这是我的代码:
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: 我删除了以下内容:
Q_EXPORT_PLUGIN2(NLPro, NLPro);
我添加了一个包含以下内容的.json文件:
{ "Keys": [ "NLPro"] }
答案 0 :(得分:0)
OP解决方案。
修正了它:
虽然
read
使用Qt 4.8正常工作我必须将其更改为
TARGET = $$qtLibraryTarget(nlpro)
for Qt 5.0