0

I'm using WebEngine in QML. Is there a way to change what gets displayed when there is a bad URL? It currently says something like:

This site can’t be reached
The webpage at qrc:/blahblah.html might be temporarily down or it may have moved permanently to a new web address.
ERR_INVALID_URL

which is inappropriate because it's not a web site, just a QML resource which is missing. Either a QML or a C++ solution would be welcome.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Paul DeRocco
  • 403
  • 3
  • 15

1 Answers1

1

For Qt WebEngine it is an invalid resource so it indicates that it is an invalid URL. A possible solution is to detect the error and load the desired HTML.

WebEngineView {
    anchors.fill: parent
    url: "qrc:/blahblah.html"
    onLoadingChanged: {
        if(loadRequest.status === WebEngineLoadRequest.LoadFailedStatus){
            var html = loadRequest.errorString;
            console.log(loadRequest.errorDomain)
            loadHtml(html);
        }
    }
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • As usual, whatever I try half works. The problem is that loadHtml() adds a new "page" to the history, so if I do what one would normally do on seeing an error, go "back", it goes back to the original error page, and then back to my error page, and not to the one before it. So I tried calling goBack() before loadHtml(). Well, no joy. I've been sticking in console.log calls to try to figure out the order in which things actually happen--with a browser, lots of stuff happens in the background after you invoke it. I haven't come up with a combination that actually works. – Paul DeRocco Jan 17 '19 at 09:24