[Development] QRC based javascript source in QWebEngineView

Scott Bloom scott at towel42.com
Tue Sep 30 23:06:43 CEST 2025


Just a note, the reason (at least for me) to the major confusion is every example that uses QWebChannel loads java script from a qrc in the html file (qrc:/qtwebchannel/qwebchannel.js)

But this issue only pops up if the top level JS calls/imports something else from the QRC

Scott

From: Scott Bloom
Sent: Tuesday, September 30, 2025 14:03
To: Kaloyan Chehlarski <kaloyan.chehlarski at qt.io>; development at qt-project.org
Subject: RE: [Development] QRC based javascript source in QWebEngineView

Thanks.  That was it.

Suggestion, and I file a bug against doc/examples if need be.

At least one of the QWebEngineXXX (potentially the recipe browser example) should show and use this.

IMO, a warning for it should be in the QWebEngineView load/setUrl commands.

Scott

From: Development <development-bounces at qt-project.org<mailto:development-bounces at qt-project.org>> On Behalf Of Kaloyan Chehlarski via Development
Sent: Tuesday, September 30, 2025 03:48
To: development at qt-project.org<mailto:development at qt-project.org>
Subject: Re: [Development] QRC based javascript source in QWebEngineView

Hi Scott,

By default, support for the Fetch API is not enabled for the QRC scheme. You can override the defaults by adding this to your main function:

QWebEngineUrlScheme qrcScheme(QByteArrayLiteral("qrc"));
qrcScheme.setFlags(QWebEngineUrlScheme::FetchApiAllowed);
QWebEngineUrlScheme::registerScheme(qrcScheme);

Make sure to read through the documentation<https://doc.qt.io/qt-6/qwebengineurlscheme.html#Flag-enum> for all the different flags you can enable. Also note that this needs to be done very early in the app's initialization stage, before any WebEngine objects are instantiated.

Cheers,
Kaloyan



Confidential
From: Scott Bloom <scott at towel42.com<mailto:scott at towel42.com>>
Date: Saturday, 27. September 2025 at 02:12
To: List for announcements regarding Qt releases and development via Announce via Development <development at qt-project.org<mailto:development at qt-project.org>>, Nuno Santos via Interest <interest at qt-project.org<mailto:interest at qt-project.org>>
Subject: [Development] QRC based javascript source in QWebEngineView
Im having problems loading html that has javascript inside of it.

I am loading the URL into the QWebEngineView  via a url that looks like QUrl( "qrc:/XXX.html" )

The top level html, uses a standard html tag for <script src="xxxx"> where xxx is always relative, there are no QRC based urls inside the html or any imported JS files.

However, it seems that the nested import commands in the JS do not look inside the QRC, and for some reason I get an error saying

js: Fetch API cannot load qrc:/pathtofile/base.json. URL scheme "qrc" is not supported.

I have confirmed that the file DOES exist from the C++ QFile based world, but Im stumped trying to figure out what is going on.

Is there anyway to track this down?

Scott


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20250930/d240a993/attachment-0001.htm>


More information about the Development mailing list