标题比较含糊,具体现象是在dll中加入webenginewidgets模块,并通过QWebEngineView打开网页。然后在main函数中通过QLibrary的load方法加载该dll,但是load既不返回true也不返回false,从任务管理器可以看出main函数所在进程已经起来了,也就是说load方法阻塞了。
解决方法:如果要在dll或者plugin中使用webenginewidgets模块,必须在main函数QApplication或QCoreApplication创建之前添加Qt::AA_ShareOpenGLContexts属性。如下所示:
#include <QLibrary>
#include <QDebug>
#include <QApplication>
typedef void (*LoadFunction)();
#define DLLPATH "testui.dll"
#define DLLPORC "loadWnd"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QApplication a(argc, argv);
QLibrary testuilib(DLLPATH);
if (testuilib.load())
{
LoadFunction pLoad = (LoadFunction)testuilib.resolve(DLLPORC);
if (pLoad)
{
pLoad();
}
}
else
{
qDebug("testui.dll load failed");
}
return a.exec();
}
