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

Problem with normalization of qrc:/ URL's

    XMLWordPrintable

Details

    Description

      It's unclear from the documentation exactly how QRC URL's should be formatted. Online documentation sometimes uses qrc:/ (for instance, http://qt-project.org/doc/qt-5/qtquick-deployment.html), and sometimes says to use qrc:/// (e.g. http://qt-project.org/doc/qt-5/qml-url.html). Within the examples, some use qrc:/// (e.g. everything under examples/quick), and some use qrc: with no slashes at all (e.g. examples/qml/referenceexamples).

      This would just be a minor point of style, except that certain forms seem to cause problems at runtime. Attached is an example of a situation where the form of the URL causes a runtime error. In this example, Foo.qml is referenced both via main.qml through an import, as well as through an explicit Qt.createComponent(). The import seems to result in the component's internal data structures using the URL qrc:///foomodule/Foo.qml, while the createComponent() call explicitly calls out the component via the URL qrc:/foomodule/Foo.qml, and creates a parallel copy with the URL set as such. An attempt to use these two forms together results in the error:

      qrc:/main.qml:17: Error: Cannot assign QObject* to Foo_QMLTYPE_0*
      

      Changing the Qt.createComponent() call to use the form qrc:/// resolves the error.

      If this is because the qrc:/ form is unsupported, then it would be helpful to have that explicitly noted in the documentation, and perhaps a slightly more useful error check added at runtime. However if the intent is to support that variant as well, then this seems to be a bug. My best guess is that the right answer would be to add some sort of normalization to the URL on the way into the QML type system, to ensure that the same scheme is used regardless of how the URL was entered.

      Attachments

        1. QmlUrlTest.zip
          1 kB
          Matt Fischer
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            fischerm Matt Fischer
            Votes:
            6 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes