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

QML module import does not implement versioning correctly

    XMLWordPrintable

Details

    Description

      Background description:
      -----------------------

      There are two different sorts of imports in QML:

      1) QML type namespace imports
      2) JavaScript resource imports

      QML object types are installed into QML type namespaces by modules.

      Modules are defined by qmldir files which describe the QML-document-defined QML object types and JavaScript resources provided by the module, as well as the C++ plugins provided by the module.

      Modules can be either:

      1) installed modules
      2) located modules

      QML object types provided by installed modules are automatically installed into a namespace defined by the module's installed path (a subdirectory of the QML import path).

      QML object types provided by located modules are automatically installed into a namespace defined by the relative directory containing the qmldir file which defines the module.

      A type namespace into which QML object types may be installed is versioned. The qmldir file defines the versioning for a located module, whereas the installed path defines the versioning of an installed module.

      Problem Statement:
      ------------------

      A client who imports a specific version of a located module does not get the types he or she expects (ie, the versioning defined in the qmldir file is not respected).

      Given the "relativeImport" directory containing the following files:

      "qmldir"
      MyType 1.0 MyType10.qml
      MyType 1.1 MyType11.qml
      MyType 2.0 MyType20.qml
      
      "MyType10.qml"
      import QtQuick 2.0
      
      Item {
          property int a: 10
      }
      
      "MyType11.qml"
      import QtQuick 2.0
      
      Item {
          property int a: 20
          property int b: 10
      }
      
      "MyType20.qml"
      import QtQuick 2.0
      
      Item {
          property bool a: true
          property string b: "hello"
      }
      

      Consider the following example:

      "test.1.qml"
      import QtQuick 2.0
      import "relativeImport"
      
      // relative import of directory with module, no version
      Item {
          MyType { id: test }
          Component.onCompleted: {
              console.log("test.a = " + test.a);
              console.log("test.b = " + test.b);
          }
      }
      
      test.2.qml
      import QtQuick 2.0
      import "relativeImport" 1.1
      
      // relative import of directory with module, with version 1.1
      Item {
          MyType { id: test }
          Component.onCompleted: {
              console.log("test.a = " + test.a);
              console.log("test.b = " + test.b);
          }
      }
      
      "test.3.qml"
      import QtQuick 2.0
      import "relativeImport" 2.0
      
      // relative import of directory with module, with version 2
      Item {
          MyType { id: test }
          Component.onCompleted: {
              console.log("test.a = " + test.a);
              console.log("test.b = " + test.b);
          }
      }
      

      When we run the test qml files with qmlscene, we get the following output:

      test.1.qml:

      test.a = 10
      test.b = undefined
      

      test.2.qml:

      test.a = 10
      test.b = undefined
      

      test.3.qml:

      test.a = true
      test.b = hello
      

      But, we expected the output for test.2.qml to be:

      test.a = 20
      test.b = 10
      

      Clearly, the minor version of a located module import is not respected.

      Attachments

        For Gerrit Dashboard: QTBUG-26473
        # Subject Branch Project Status CR V

        Activity

          People

            mvogt Matthew Vogt (closed Nokia identity) (Inactive)
            chriadam Christopher Adams (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes