【发布时间】:2016-05-23 03:06:11
【问题描述】:
我正在将 Qt 5.5、QWebView 项目移植到 Qt 5.6(测试版)、QWebEngine。我已经阅读了移植指南here。我的代码如下所示:
.h 文件定义 _view 如下:
QWebEngineView* _view;
.cpp 构造函数(类继承自 QWidget)有:
QVBoxLayout* vbox = new QVBoxLayout(this);
_view = new QWebEngineView(this);
connect(_view, SIGNAL(loadFinished(bool)), this, SLOT(loadPageFinished(bool)));
QString webDir = getReportBasePath() + no_tr("/index.html#") + startingPage;
// QWebEnginePage *page = _view->page(); // <-- CRASH!!
_view->load( QUrl("file:///" + webDir ) ); // <-- CRASH!!
_view->show();
vbox->addWidget(_view);
在执行 page() 或 load() 方法时,整个事情都会崩溃:
Unhandled exception at 0x67019C66 (Qt5Cored.dll) in qxs.exe: 0xC0000005:
Access violation reading location 0x00000000.
我已验证 _view 指针不为空。
如果您查看文档,他们有一个示例 here 几乎与我上面的代码相同。我还尝试将 load() 调用替换为与他们的相同:
view->load(QUrl("http://qt-project.org/"));
它仍然崩溃。任何想法可能导致这些崩溃?
我需要先创建一个 QWebEnginePage 并在 QWebEngineView 上 setPage() 吗? (我假设不是......)它是否与我正在使用的 Qt 二进制文件(为 Windows 32 位 MSVC 2013 预构建)有关?
堆栈跟踪的相关部分:
Qt5WebEngineWidgetsd.dll!QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile * _profile) Line 95 C++
Qt5WebEngineWidgetsd.dll!QWebEnginePage::QWebEnginePage(QObject * parent) Line 393 C++
Qt5WebEngineWidgetsd.dll!QWebEngineView::page() Line 145 C++
Qt5WebEngineWidgetsd.dll!QWebEngineView::load(const QUrl & url) Line 157 C++
qxs.exe!ReportWidget::ReportWidget(QcaMain * qm, QWidget * parent, QString startingPage) Line 321 C++
这里崩溃了:
QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile)
: adapter(new WebContentsAdapter)
, history(new QWebEngineHistory(new QWebEngineHistoryPrivate(this)))
, profile(_profile ? _profile : QWebEngineProfile::defaultProfile())
, settings(new QWebEngineSettings(profile->settings()))
, view(0)
, isLoading(false)
, scriptCollection(new QWebEngineScriptCollectionPrivate(browserContextAdapter()->userScriptController(), adapter.data()))
, m_backgroundColor(Qt::white)
, fullscreenMode(false)
{
memset(actions, 0, sizeof(actions));
}
我认为这可能与 _profile 为 NULL 有关,因此我尝试首先像这样设置 QWebEngineProfile:
QWebEnginePage* page = new QWebEnginePage( QWebEngineProfile::defaultProfile(), _view );
_view->setPage( page );
然后它会在此处的 qwebengineprofile.cpp 中崩溃:
static QWebEngineProfile* profile = new QWebEngineProfile(
new QWebEngineProfilePrivate(BrowserContextAdapter::defaultContext()),
BrowserContextAdapter::globalQObjectRoot());
带有堆栈跟踪:
Qt5Cored.dll!convert_to_wchar_t_elided(wchar_t * d, unsigned int space, const char * s) Line 256 C++
Qt5Cored.dll!qt_message_fatal(QtMsgType __formal, const QMessageLogContext & context, const QString & message) Line 1593 C++
Qt5Cored.dll!QMessageLogger::fatal(const char * msg, ...) Line 784 C++
Qt5WebEngineCored.dll!`anonymous namespace'::subProcessPath(void) C++
Qt5WebEngineCored.dll!WebEngineLibraryInfo::getPath(int) C++
Qt5WebEngineCored.dll!WebEngineContext::WebEngineContext(void) C++
Qt5WebEngineCored.dll!WebEngineContext::current(void) C++
Qt5WebEngineCored.dll!QtWebEngineCore::BrowserContextAdapter::defaultContext(void) C++
> Qt5WebEngineWidgetsd.dll!QWebEngineProfile::defaultProfile() Line 516 C++
【问题讨论】:
-
请向我们展示该崩溃的回溯。
-
好的,我有一个堆栈跟踪。我将更新我的原始帖子以包含新信息。
-
知道如何在 osx 上解决这个问题吗?
标签: qt qtwebengine qt5.6