Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. version number for QML imports
Forum Updated to NodeBB v4.3 + New Features

version number for QML imports

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 2.7k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • VStevenPV Offline
    VStevenPV Offline
    VStevenP
    wrote on last edited by VStevenP
    #1

    In QML code, is it recommended to specify the lowest import version number you can, or the highest import version you can?

    I have tended to use the lowest import version number I can, so I keep at the most minimum QML "API" for the features I need, and also so my QML could work on older Linux systems that have an older version of Qt 5 libraries.

    I wonder if that approach can cause any drawbacks on a more up-to-date system that has more up-to-date Qt libraries - for example, could I be missing code optimizations, fixes, etc.

    I guess I am wondering about any tradeoffs between "import version number" and "optimal code execution".

    Perhaps the recommendation will be to use the QML Profiler and see if there is any difference, and pick the one that best suits the situation.

    Still, I wonder if there is a general recommendation.

    sierdzioS 1 Reply Last reply
    1
    • VStevenPV VStevenP

      In QML code, is it recommended to specify the lowest import version number you can, or the highest import version you can?

      I have tended to use the lowest import version number I can, so I keep at the most minimum QML "API" for the features I need, and also so my QML could work on older Linux systems that have an older version of Qt 5 libraries.

      I wonder if that approach can cause any drawbacks on a more up-to-date system that has more up-to-date Qt libraries - for example, could I be missing code optimizations, fixes, etc.

      I guess I am wondering about any tradeoffs between "import version number" and "optimal code execution".

      Perhaps the recommendation will be to use the QML Profiler and see if there is any difference, and pick the one that best suits the situation.

      Still, I wonder if there is a general recommendation.

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @VStevenP said in version number for QML imports:

      In QML code, is it recommended to specify the lowest import version number you can, or the highest import version you can?

      Lowest. This gives you most flexibility, while not losing any optimisations and features.

      But in truth - it does not matter. Internally, QML engine always loads the newest code it has. There even was a plan to completely drop module versioning in Qt 6, but it didn't happen (yet).

      I have tended to use the lowest import version number I can, so I keep at the most minimum QML "API" for the features I need, and also so my QML could work on older Linux systems that have an older version of Qt 5 libraries.

      I wonder if that approach can cause any drawbacks on a more up-to-date system that has more up-to-date Qt libraries - for example, could I be missing code optimizations, fixes, etc.

      No, you're not missing anything this way, and you leave a "door open" to lower Qt version if you need to, without having to manually change all import statements in all QML files.

      I guess I am wondering about any tradeoffs between "import version number" and "optimal code execution".

      Perhaps the recommendation will be to use the QML Profiler and see if there is any difference, and pick the one that best suits the situation.

      Still, I wonder if there is a general recommendation.

      General recommendation is "it does not matter, we ignore version numbers anyway" ;)

      (Z(:^

      1 Reply Last reply
      2
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by fcarney
        #3

        @sierdzio

        But it can affect properties available in objects:

        import QtQuick 2.14
        
        Image {
          sourceClipRect: Qt.rect(0,0,100,100)
        }
        

        Result:

        QQmlApplicationEngine failed to load component
        qrc:/main.qml:352:9: "Image.sourceClipRect" is not available in QtQuick 2.14.
        

        Once I increase that value to 2.15 it works fine.

        Are you talking about something else?

        C++ is a perfectly valid school of magic.

        sierdzioS 1 Reply Last reply
        0
        • VStevenPV Offline
          VStevenPV Offline
          VStevenP
          wrote on last edited by
          #4

          Based on all the statements he made, I think he's saying the imports just control the API (what properties are available), but that beyond that, it is always using the latest code. So, it's really just an API control.

          Therefore, it makes sense to use the lowest numbered import statements if you wish to limit the API in your code, in the case your code needs to run on an older version of Qt and you wish to ensure it will not use any features unavailable in that version.

          Thanks for your answers. I am going to mark this Resolved.

          1 Reply Last reply
          1
          • fcarneyF fcarney

            @sierdzio

            But it can affect properties available in objects:

            import QtQuick 2.14
            
            Image {
              sourceClipRect: Qt.rect(0,0,100,100)
            }
            

            Result:

            QQmlApplicationEngine failed to load component
            qrc:/main.qml:352:9: "Image.sourceClipRect" is not available in QtQuick 2.14.
            

            Once I increase that value to 2.15 it works fine.

            Are you talking about something else?

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            @fcarney said in version number for QML imports:

            But it can affect properties available in objects:

            Yes, and OP is aware of it:

            I have tended to use the lowest import version number I can, so I keep at the most minimum QML "API" for the features I need

            So in my answer I focused on other stuff.

            Of course, you should not lower the number so much that you start loosing features you need :-)

            (Z(:^

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved