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

QWebEngineScript::setSourceUrl doesn't load scripts from qrc

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 6.2.0, 6.2.1
    • 6.2.0 Beta4
    • WebEngine
    • None
    • All
    • ce2d6a94ce99f8d6f82fbcbf45603f8eb7a92957 (qt/qtwebengine/6.2) 5838af270052c8befe31f9ddcf29d02bb0a5084a (qt/qtwebengine/6.2.0) f33badbaa4 (qt/qtwebengine/dev) ce68f52bbf (qt/qtwebengine/6.3) ce68f52bbf (qt/qtwebengine/6.3.0)

    Description

      QWebEngineScript::setSourceUrl doesn't load scripts from qrc, i.e it can't be used such way:

      QWebEngineScript script;
      script.setSourceUrl(QUrl("qrc:///qtwebchannel/qwebchannel.js"));
      ...
      

      or in QML:

      let script = WebEngine.script()
      script.sourceUrl = "qrc:///qtwebchannel/qwebchannel.js"
      ...
      

      There is wrong code introduced by https://codereview.qt-project.org/c/qt/qtwebengine/+/311566

      void QWebEngineScript::setSourceUrl(const QUrl &url)
      {
          if (url == sourceUrl())
              return;
      
          d->setSourceUrl(url);
      
          QFile file;
          if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0) {
              if (url.authority().isEmpty()) // <---- wrong?
                  file.setFileName(QLatin1Char(':') + url.path()); 
              return;  //  <---- wrong!                        
          } else {
              file.setFileName(url.toLocalFile());
          }
      
          if (!file.open(QIODevice::ReadOnly)) {
              qWarning() << "Can't open user script " << url;
              return;
          }
      
          QString source = QString::fromUtf8(file.readAll());
          setSourceCode(source);
      }
      

      Attachments

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

        Activity

          People

            allan.jensen Allan Sandfeld Jensen
            studiosus Vladimir Belyavsky
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes