[Interest] Support for Qt 5 & Qt 6 in QML app
Ulf Hermann
ulf.hermann at qt.io
Fri May 13 09:40:17 CEST 2022
Hi,
> I need to migrate a Qt 5 application with QML ui to Qt 6 without
> losing Qt 5 support. What is the best approach here? Version-specific
> resources? File selectors (by the way is it even possible to select
> QML files based on the Qt version?) I mean it is clear that
> platform-specific code/imports needs to be wrapped into
> platform-specific components, but what is the best way to select the
> right component?
File selectors are generally not a great idea as we cannot know ahead of
time what they will evaluate to at run time. What concrete problems are
you facing? Most QML code written for Qt 5 should still work with Qt 6.
You can use qmldir imports to select between different modules based on
Qt version. By constructing your qmldir files from the build system you
can change what your module imports at compile time. Unfortunately we
don't have a good API for defining QML modules in Qt5. The only thing we
have there is CONFIG+=qmltypes in qmake. You need to write build system
code that generates or copies the qmldir file into place.
qmldir imports have a number of quirks in Qt5. They pretty much only
work when the import statement is in a qmldir file of a QML module that
also defines some other types. The other types have to be implemented in
C++ and there must not be any *.qml files in the same module. In Qt6,
qmldir imports are less of a pain.
best regards,
Ulf
More information about the Interest
mailing list