gpt4 book ai didi

qt - 奇怪的错误 : "error loading plugin. The specified module could not be found"

转载 作者:行者123 更新时间:2023-12-03 23:45:14 26 4
gpt4 key购买 nike

我尝试使用以下代码加载我的插件:

QString path = QFileDialog::getOpenFileName(0);
QPluginLoader loader(path);
AnprPluginInterface *i = qobject_cast< AnprPluginInterface* >(loader.instance());
if (i == NULL )
QMessageBox::information(0, "this", "error loading plugin." + loader.errorString());
else
QMessageBox::information(0, "this", "plugin loaded.");

我将插件的绝对路径发送到 QPluginLoader但它说找不到插件!
错误是:
error loading plugin. "Cannot load library The specified module could not be found." 

最佳答案

您确定您的插件使用 Q_INTERFACES() 宏导出了正确的接口(interface)吗?如果您收到错误,您有两个可能的事情要检查:

1) loader.instance() 返回 0:在这种情况下,您必须调查报告的错误。

2) qobject_cast 返回 0:在这种情况下,我认为问题出在缺少导出的接口(interface)上。

此外,您应该考虑到您的两个执行路径都在执行相同的代码,所以也许您根本没有收到错误......我指的是这个:

if (i == NULL )
// Reports the error
QMessageBox::information(0, "this", "error loading plugin." + loader.errorString());
else
// Hey!? WTF!? Repots the error anyway!?
QMessageBox::information(0, "this", "error loading plugin." + loader.errorString());

3)我忘记了:还要检查插件和应用程序是否以相同的方式构建(调试/发布)。

4)顺便说一句,应该检查的另一件事是插件是否带有一些依赖项(例如其他动态库)。它发生在我身上一次,我花了很长时间才发现我丢失了一个 DLL,这导致我的插件无法正确加载!

关于qt - 奇怪的错误 : "error loading plugin. The specified module could not be found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17920303/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com