Usually my QML files start with import QtQuick 2.4
and other imports. How can I know which is the latest version of the imported modules without having to guess by type and build?

- 1,724
- 3
- 19
- 38
-
1Read the release notes. – dtech Aug 14 '15 at 13:18
-
I guess the real question is: why do you think that you need to know it, since most likely it's for the wrong reasons... – Kuba hasn't forgotten Monica Aug 14 '15 at 18:50
-
3I think this is a very good question, and it's been brought up before. There's been talk of adding the ability to leave off the version number on imports and have it import the latest version, which I think is a great idea. Having to go to the documentation to see which version to import when it almost always doesn't matter is annoying. – Mitch Aug 15 '15 at 07:21
-
[QTBUG-38304](https://bugreports.qt.io/browse/QTBUG-38304) has this suggestion, although it's a bit drawn out and would be a better suggestion if it was just "QQmlEngine should import the latest available version of a module if the version number is omitted". – Mitch Aug 15 '15 at 07:28
2 Answers
You basically don't have to know. By importing a particular version, you merely declare that you don't need the additional functionality of any potentially newer version. That doesn't mean that you won't use a newer version if one is available - it simply means that your code will refuse to run if only an older version than the one you need is present.
So, you should only change the imported module version if you happen to use the functionality (members, classes, etc.) from a newer version. That's all. And you will know exactly what version you need, since you're using the functionality you read about in the documentation. The documentation will state what module version it applies to.
The documentation for a given Qt Quick module from the Qt that you're using will state this - no need for release notes.

- 95,931
- 16
- 151
- 313
-
3How does one find the module version in the documentation? For example, looking at the QtQuick Row.padding documentation, it states that the property is available since Qt 5.6, but what version of QtQuick corresponds to Qt 5.6? Update: I see there is an import statement at the top of the doc page for the current/latest version of Qt, but I'd like to see a table of the correspondences between Qt releases and module versions (does one exist?) – DavidJ Jan 23 '17 at 17:23
-
7@DavidJ see **Versions** section [here](https://doc.qt.io/qt-5/qtquickcontrols2-index.html) – rsht Oct 19 '17 at 15:00
-
-
3This is such a wrong answer, why was it accepted? Anyone who comes across this is wanting to understand how to properly version their imports, most likely so that they can target older systems (e.g. `Ubuntu 16.04`). There are two practical approaches here: (1) understand what features were added in what versions or (2) understand what versions a target platform supports. In neither case is "You basically don't have to know" correct. – notlesh Oct 21 '19 at 20:10
-
1@notlesh When you use a feature, Qt documentation states exactly what import version you need. If that version is not available on a platform, your application simply can't run there (not without custom Qt). If you need to see what's available in any particular Qt version, look at that version's documentation and design to that. You'll find the default Qt version in the distro's resources (package list, etc.). – Kuba hasn't forgotten Monica Oct 22 '19 at 12:00
The QML module version information can be found in a file called plugins.qmltypes. These files use JSON to store information (as far as I am aware). In these files Qt uses the "exports" specifier to export the name and version of a module.
Example: exports: ["QtQuick/Accessible 2.0"]
The example shows the version of the QtQuick.Accessible module. The plugins.qmltypes are stored in a directory of the same name as base level module. In the case of the example this would be QtQuick. Base level modules are grouped under a directory titled qml. That is "usually" located in a directory called qtx (in some case Qt). Where x is the installed major version of Qt (in my case it would be qt5). That means the plugins.qmltypes has a path that looks something like this:
/qt5/qml/QtQuick/plugins.qmltypes
The reason im explaining this bottoms up cause the rest of the path is dependent on how you installed Qt:
Package manager (portage) amd64 install path:
/usr/lib64/qt5/qml/
pip PySide6 install path:
~/.local/lib/python3.9/site-packages/PySide6/Qt/qml/
pip PyQt6 install path:
~/.local/lib/python3.9/site-packages/PyQt6/Qt6/qml
~/.local/lib/python3.9/site-packages/PyQt6/Qt6/qml
Package manager (apt) aarch64 install path:
/usr/lib64/aarch64-{forgot this part}-/qt5/qml/
I figure the version out in bulk with:
grep -r "exports:.*\\]" <insert install/OS dependent path>/qml/* | less
This doesnt grab multiple exports that are spread over multiple lines thought.
Since QML comes in 2 major versions when in doubt you could import version 1.0 or 2.0.

- 2,377
- 7
- 20
- 39