OK, I did so:
/qml_ui/qt5compat/MessageDialog.qml:
import QtQuick 2.0
import "./qt5"
import "./qt6"
MessageDialog
{
}
/qml_ui/qt5compat/qt5/MessageDialog.qml :
import QtQuick 2.0
import QtQuick.Dialogs 1.3
MessageDialog
{
readonly property int buttonOk: StandardButton.Ok
readonly property int buttonCancel: StandardButton.Cancel
property int buttons: buttonOk
standardButtons: buttons
}
/qml_ui/qt5compat/qt6/MessageDialog.qml:
import QtQuick 2.0
import Qt.labs.platform 1.1 as QtLabs
QtLabs.MessageDialog
{
readonly property int buttonOk: MessageDialog.Ok
readonly property int buttonCancel: MessageDialog.Cancel
buttons: buttonOk
}
Now, the only I need to use MessageDialog in both Qt5 and Qt6 is to:
import "./qt5compat"
MessageDialog {
buttons: buttonOk | buttonCancel
}
And I have two additional resource files. One is included for Qt5 and
contains files inside of /qml_ui/qt5compat/qt5 folder and the similar
one for Qt6.
One note also: under Qt5, /qml_ui/qt5compat/qt6 folder must still exist.
The same for Qt6: /qml_ui/qt5compat/qt5 must exist. To achieve this,
I've just added to blank files to common resource file.
:)
On 9/7/2021 11:13 PM, Alexander Dyagilev wrote:
Hello,
We would like to migrate to Qt6. However, we still need to be able to
build our project with Qt5 to continue supporting Windows 7 OS (15% of
our users are still using it).
For now, I've managed to make C++ part support both Qt6 and Qt5.
However, it seems that QML part is not so easy.
For example, we do use MessageDialog component. In Qt5, it requires
import QtQuick.Dialogs 1.3, and in Qt6 - import Qt.labs.platform 1.1.
Is it possible to import different modules depending on the current Qt
version?
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest