QWebView works perfectly in Qt4.8, fails in Qt5.0
-
I have a QWebView that opens a local web page on my computer, and everything works perfectly in Qt4.8. (It also works with a browser). But after porting the software to Qt5.0 (and making the change from QWebView to QtWebKitWidgets/QWebView, I get the failure return from loadFinished().
Here's the code: @HelpManager::HelpManager(QObject *parent) :
QObject(parent)
{
view = new QWebView();
connect (view, SIGNAL(loadStarted()), SLOT(loadIsStarted()));
connect (view, SIGNAL(loadProgress(int)), SLOT(loadInProgress(int)));
connect (view, SIGNAL(loadFinished(bool)), SLOT(loadIsFinisehd(bool)));
view->load(QUrl("../Help/IDTNVMeMgr-web/index.html"));
view->setWindowTitle("IDTVMeMgr Help Information");
view->show();
}
void HelpManager::loadIsStarted()
{
qDebug() << "loadIsStarted";
}void HelpManager::loadInProgress(int progress)
{
qDebug() << "loadInProgress, progress =" << progress;
}void HelpManager::loadIsFinisehd(bool isOk)
{
qDebug() << "loadIsFinshed, status = " << isOk;
} @Here is the successful output using Qt4.8
@loadIsStarted
loadInProgress, progress = 10
loadInProgress, progress = 10
loadInProgress, progress = 27
loadInProgress, progress = 29
loadInProgress, progress = 32
loadInProgress, progress = 36
loadInProgress, progress = 36
loadInProgress, progress = 36
loadInProgress, progress = 90
loadInProgress, progress = 90
loadInProgress, progress = 90
loadInProgress, progress = 90
loadInProgress, progress = 90
loadInProgress, progress = 100
loadIsFinshed, status = true @And here is the failure using Qt5.0
@loadIsStarted
loadInProgress, progress = 10
loadIsFinshed, status = false
loadInProgress, progress = 100 @Does anybody have any ideas?
-
At a guess, the process' current working directory is not what you think it is rendering the relative path (line 8) to the file invalid.
-
I too suspected that it wasn't finding the file at the relative path, however, I added qDebug() << "curDir = " << QDir::currentPath();
and it returned the correct path. Also I added a call to
File::exists ("../Help/IDTNVMeMgr-web/index.html") and it returned true. Finally I changed the path in load(QUrl("../) from a relative path to an absolute path, and still got the same failure. -
Well I guess the next stop is to subclass QWebPage, implement extension()/supportsExtension() and handle QWebPage::ErrorPageExtension calls. You should receive an ErrorPageExtensionOption object containing a useful error message.
-
I put solving this problem aside due to other pressing concerns, however I need to get it to work now. I have since upgraded to Qt5.02, and for the MSVC++ version, I still get the same results as above. But for the Qt5.02 MinGW version, it is even worse. The program at first seems to hang, but after a long time, it crashes with the following output:
QIODevice::read: maxSize argument exceeds QByteArray size limit.
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc -
Completely untested, but IIRC Qt 5 is way more picky about QUrls... Try using
@view->load(QUrl::fromLocalFile("../Help/IDTNVMeMgr-web/index.html"));@ -
The suggested change at least keeps the program from crashing for Qt5.02 MinGW version, but I still only get a black window displayed.