Hello,

I've just created a separate qt5compat folder inside of directory with my QML code.

Let's suppose I need to use RectangularGlow component. For this I've created 3 files:

1. qt5compat/RectangularGlow.qml with the following contents:

import QtQuick 2.0
import "./qt5"
import "./qt6"

RectangularGlow
{

}

2. qt5compat/qt5/RectangularGlow.qml with the following contents:

import QtQuick 2.0
import QtGraphicalEffects 1.0

RectangularGlow
{

}

This file should be included into resource only when compiling using Qt5.

3. qt5compat/qt6/RectangularGlow.qml with the following contents:

import QtQuick 2.0
import Qt5Compat.GraphicalEffects

RectangularGlow
{

}

This file should be included into resource only when compiling using Qt6.

Now, all I need to use RectangularGlow in my QML code is to import my custom component:

import "./qt5compat"

How to conditionally include resources: I've just created 2 separate files for this my simple qt5compat "library": qmlqt5compat_qt5.qrc and qmlqt5compat_qt6.qrc. Then, in my .pro file:

greaterThan(QT_MAJOR_VERSION, 5):RESOURCES += qmlqt5compat_qt6.qrc
lessThan(QT_MAJOR_VERSION, 6):RESOURCES += qmlqt5compat_qt5.qrc

Hope this helps :)


On 4/25/2022 10:41 AM, Александр Иваш wrote:
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?
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to