Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-101040

WebView qml element does not find qrc: html file

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.2.0, 6.2.2
    • WebEngine
    • None
    • fedora 34/36 gcc11/gcc12 respectivelly.
    • Linux/Wayland

    Description

      In Fedora, after moving from qt 5 to qt 6 

      the webview class cannot find the HTML file in the qt resource system

      This only happens in Fedora. tried in fedora 34, and 36. does not happen under Ubuntu 18/20.

       

      here is an example project

      qml:

      import QtQuick 2.0
      import QtQuick.Window 2.0
      import QtWebEngine 1.0
      
      Window {
          width: 1024
          height: 750
          visible: true
          WebEngineView {
              anchors.fill: parent
              url: urlToLoad
              onLoadingChanged: function(info) {
              console.log("Loading changed ... Status = ", info.status)
              console.log(info.errorString)
              }
          }
      }
      

      cmake:

      add_executable(webcrash
              webcrash_main.cpp
              webcrash.qrc
              )
      
      target_link_libraries(webcrash PUBLIC
              Qt6::Widgets
              Qt6::QuickControls2
              Qt6::WebChannel
              Qt6::WebEngineCore
              Qt6::WebEngineWidgets
              Qt6::WebEngineQuick
              )
      
      install(TARGETS webcrash)
      
      

      index.html:

      <!DOCTYPE html>
      <html lang="en">
      <head>
          <meta charset="UTF-8">
          <title>Title</title>
      </head>
      <body>
      Super Simple Hello
      </body>
      </html>
      

      webcrash.qrc:

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

      webcrash_main.cpp

      #include <QGuiApplication>
      #include <QtWebEngineQuick>
      #include <QQmlApplicationEngine>
      #include <QtWebEngineCore>
      #include <iostream>
      
      int main(int ac, char **av) {
          QtWebEngineQuick::initialize();
          QGuiApplication app(ac, av);
      
          QQmlApplicationEngine engine;
          engine.rootContext()->setContextProperty("urlToLoad", "qrc:///index.html");
          engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
      
          QCommandLineParser parser;
          parser.setApplicationDescription(
              "Minimal QWebEngine");
          parser.addHelpOption();
          parser.addVersionOption();
      
          QCommandLineOption clear_settings_option("url",
                                                   "URL to load",
                                                   "urlToLoad",
                                                   "");
          bool x = parser.addOption(clear_settings_option);
          assert(x);
          if(x){
              ;;
          }  // Create a QDir that points out to your path in the resources folder
      
          parser.process(app);
          auto v =parser.value(clear_settings_option);
          if (!v.isEmpty())
          {
              engine.rootContext()->setContextProperty("urlToLoad", v);
          }
          // Create a QDir that points out to your path in the resources folder
          QDir directory(":/");
          // Load all files with the *.PNG extension
          // (you can modify this to suit your needs.
          QStringList resource_list = directory.entryList();
          for (auto &i : resource_list) {
      
              std::cout<< "FILE: " << i.toStdString() <<"\n";
          }
          return app.exec();
      }
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt_webengine_team Qt WebEngine Team
            gabrielsallum gabriel sallum
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes