<div dir="ltr"><div dir="ltr"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le dim. 19 juin 2022 à 13:05, Albert Astals Cid <<a href="mailto:aacid@kde.org">aacid@kde.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">El dissabte, 18 de juny de 2022, a les 14:24:21 (CEST), Johnny Jazeix va <br>
escriure:<br>
> Hi,<br>
> <br>
> for GCompris (compiled in Qt5 only), we have activities using the Calendar<br>
> qml object.<br>
> <br>
> Previously, we imported the one from QtQuick.Controls 1 but this module has<br>
> been deprecated and we switched to QtQuick.Controls 2. This component<br>
> hasn't been implemented in QtQuick.Controls 2 before Qt6.3 (via "import<br>
> QtQuick.Controls").<br>
> <br>
> This one is available in Qt Marketplace (<br>
> <a href="https://code.qt.io/cgit/qt-extensions/qtquickcalendar.git" rel="noreferrer" target="_blank">https://code.qt.io/cgit/qt-extensions/qtquickcalendar.git</a>) and supports Qt5<br>
> and Qt 6.0-> 6.2 (via "import QtQuick.Calendar 1.0") but requires<br>
> QtControls private headers to be installed and they are not present on some<br>
> distributions (Ubuntu < 21.04...), which we would like to still support for<br>
> the next version.<br>
> <br>
> There is the one in Qt.labs which is available in Qt5 but not Qt6 (via<br>
> "import Qt.labs.calendar 1.0").<br>
> <br>
> GCompris' code works fine with any of the import (<br>
> <a href="https://invent.kde.org/education/gcompris/-/blob/master/src/activities/calen" rel="noreferrer" target="_blank">https://invent.kde.org/education/gcompris/-/blob/master/src/activities/calen</a><br>
> dar/Calendar.qml#L14) but I didn't find any "if(Qt_version < ...) use one,<br>
> else the other" except doing a Calendar.qml.cmake with a @GOOD_IMPORT@ that<br>
> would be set by cmake and a configure_file.<br>
> Is there a better way?<br>
> <br>
> For now, we only target Qt5, so we could use Qt.labs without having to<br>
> handle the other two but once we switch to Qt6, we will face the issue with<br>
> distributions using Qt6.2 so I'd rather prepare this transition sooner than<br>
> later.<br>
<br>
As you have found, tou need to have two different codebases for Qt5 and Qt6.<br>
<br>
QML doesn't have "ifdef", the only way I've been able to simulate something <br>
like in pure QML that is having a Loader loads "the old version" and then <br>
reacting to the Loader status changing to Loader.Error and trying to old "the <br>
new version".<br>
<br>
Another somewhat less ugly way way is simply having a C++ singleton or <br>
something that tells you the Qt version and then also using a Loader to do the <br>
same<br>
<br>
Loader {<br>
source: Singleton.isQt6 ? "Qt6Code.qml" : "Qt5Code.qml"<br>
}<br>
<br></blockquote><div><br></div><div>
Thank you for confirming there is no "clean" (as without duplicating the code) way to do it.</div><div>I've still used the "configure_file" solution as it is the one that does not duplicate files.</div><div><br></div><div>Cheers,</div><div>Johnny<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Cheers,<br>
Albert<br>
<br>
> <br>
> Cheers,<br>
> <br>
> Johnny<br>
<br>
<br>
<br>
<br>
</blockquote></div></div>