QWebEngineView - loading html from resources

I am currently playing with QWebEngineView

in Qt 5.8 and I would like to load a file index.html

from my file .qrc

.

My file .pro

looks like this:

TEMPLATE = app
TARGET = Launcher
QT += webenginewidgets
CONFIG += c++14

SOURCES += main.cpp

RESOURCES += \
    launcher.qrc

      

My file main.cpp

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();
}

      

My project has a file launcher.qrc

:

<RCC>
    <qresource prefix="/html">
        <file>index.html</file>
    </qresource>
</RCC>

      

Inside, index.html

I just added the text Hello World

without any others.

When I run the application, I just get a "Website not re-running" error screen.
Then I googled and tried several different attempts to specify the resource url for mine 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 no longer receive this error page other than a blank page. If I then touch the window and select View Page Source, the page source is also empty.

I recently got this working with a fresh Qt Quick Application built with Qt Creator 4.2.2 using the same url qrc:...

.
Now I have created a Qt Widgets app and it doesn't work anymore.
What am I missing here?

+3


source to share


1 answer


As suggested, I'll put the solution from the comments above as an answer for future users having the same problem.



"[...] I accidentally cleaned the project and clicked Run qmake and then ran the project again. This time it worked with any of the three URLs. It's so frustrating. Thanks for the help @ deW1"

+3


source







All Articles