2016-02-12 182 views
4

我正在将Qt 5.5,QWebView项目移植到Qt 5.6(beta),QWebEngine。我已经通过移植指南here。我的代码如下所示:QWebEngineView在加载()或页面()方法崩溃

.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); 

一旦这样无论是页面()或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/")); 

它仍然崩溃。任何想法可能导致这些崩溃?

我是否需要先在QWebEngineView上创建QWebEnginePage并设置页面()? (我假设不是......)它可能与我正在使用的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是空的,所以我试图先设置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++ 
+0

显示我们回溯了那一声请。 –

+0

好的,我有一个堆栈跟踪。我会更新我的原始文章以包含新信息。 –

+0

关于如何在osx上解决这个问题的任何想法? –

回答

5

问题解决了。我错过了QWebEngine所需的一些关键文件,否则会崩溃。这些文件必须与可执行文件位于同一目录中。他们被windeployqt.exe工具放在那里,所以这是确保你的Qt应用程序具有所有需要运行而不会崩溃的最佳方式。

qtwebengine_resources.pak 
qtwebengine_resources_100p 
qtwebengine_resources_200p.pak.pak 
QtWebEngineProcess.exe 
icudtl.dat 

这让我为我们的开发团队的前身是使用Qt 4.8,并使用一个内部方法来复制所需的Qt DLL和诸如此类的东西到目标目录的原因。当升级到Qt 5.x并添加QWebEngine时,我们并没有意识到上述文件是必需的。

1

您可以设置名为Windows环境变量QTWEBENGINEPROCESS_PATH

例子:

QTWEBENGINEPROCESS_PATH C:\Qt\Qt5.6.0\5.6\msvc2013_64\bin\QtWebEngineProcess.exe 

通过这一解决方案,没有必要的资源文件复制到你的项目输出文件夹

相关问题