I'm currently playing around with QWebEngineView
in Qt 5.8 and I would like to load an index.html
file from my .qrc
file.
My .pro
file looks like this:
TEMPLATE = app
TARGET = Launcher
QT += webenginewidgets
CONFIG += c++14
SOURCES += main.cpp
RESOURCES += \
launcher.qrc
My main.cpp
file looks like this:
#include <QApplication>
#include <QWebEngineView>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWebEngineView view;
view.load(QUrl("qrc:/html/index.html"));
view.resize(1024, 768);
view.show();
return a.exec();
}
In my project there is a launcher.qrc
file:
<RCC>
<qresource prefix="/html">
<file>index.html</file>
</qresource>
</RCC>
Inside index.html
I just added the text Hello World
without anything else.
When I start the application I just get a "Website not reacheable" error screen.
I then googled around and tried several different attempts to specify the resource url to my QWebEngineView
:
view.setUrl(QUrl("qrc:/html/index.html")); // Same error page
view.page()->setUrl(QUrl("qrc:/html/index.html")); // Same error page
view.page()->load(QUrl("qrc:/html/index.html")); // Same error page
If I change the resource url from qrc:/html/index.html
to :/html/index.html
I don't get this error page anymore but a blank page instead. If I then rightclick the window and select "View page source" the page source is empty, too.
I recently got this working with a fresh Qt Quick Application created with Qt Creator 4.2.2 using the same qrc:...
url.
Now I created a Qt Widgets Application and it doesn't work anymore.
What am I missing here?
Heading
Something
– deW1 Apr 30 '17 at 14:58