[Development] QML preprocessor

Pierre-Yves Siret py.siret at gmail.com
Mon Mar 18 10:11:29 CET 2019


Hello,

This can be done with QQmlFileSelector :

    QQmlApplicationEngine engine;
    QQmlFileSelector* qmlFileSelector = QQmlFileSelector::get(&engine);

#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
    qmlFileSelector->setExtraSelectors({"5.12"});
#endif

    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

This will load qrc:/+5.12/main.qml (if there's one) instead of
qrc:/main.qml when the Qt version is >= 5.12.

Cheers,
Pierre-Yves

Le lun. 18 mars 2019 à 09:13, Albert Astals Cid via Development <
development at qt-project.org> a écrit :

> El diumenge, 17 de març de 2019, a les 13:34:09 CET, Alberto Mardegan va
> escriure:
> > Hi there!
> >   When developing a QML module for the greater public one wants to
> > provide a source package that can be built on multiple Qt versions.
> > However, QML's lack of a preprocessor makes this rather cumbersome.
> >
> > Suppose that my module needs to provide an element like this:
> >
> > ====
> > import QtQuick 2.10
> >
> > Item {
> >     ...
> >     Flickable {
> >         boundsMovement: Flickable.StopAtBounds
> >         ...
> >     }
> > }
> > ====
> >
> > If I wanted to make this available to users of Qt 5.9 and older, I'd
> > need to ship another file, instead, importing QtQuick 2.9 and removing
> > that "boundsMovement" property.
> >
> > Keeping two or more copies of the same file and installing the proper
> > one depending on the Qt version is certainly doable, but it carries a
> > considerable maintenance cost.
> >
> > I've personally decided to keep a single copy of each QML file but use
> > different git branches; however, this also has its maintenance costs and
> > makes things harder for people using the project, in that they need to
> > checkout the right branch of the project, otherwise it won't work on
> > their machines.
> >
> > Has this problem been recognized and discussed before?
>
> We have fixed this problem in some places by using a Loader that changes
> the source on loading error
>
> MyItem.qml code (which is what users of the code are supposed to use would
> be)
> Item
> {
>         Loader {
>                 source: "MyItemForQuick210.qml"
>                 onStatusChanged: if (loader.status == Loader.Error) source
> = "MyItemForQuick26.qml"
>         }
> }
>
> Not real code so may not "compile", but you should get the idea.
>
> It's not awesome but for our use-case it worked.
>
> Cheers,
>   Albert
>
> > Would a QML
> > preprocessor be a viable option?
> > I understand that this is not a problem for Qt itself, and it's a minor
> > problem for app developers; however, developing a portable QML module
> > depending on QtQuick is nearly impossible due to this, unless one agrees
> > to settle on a certain old version of Qt and renounce to all the goodies
> > that were added in later versions.
> >
> > Ciao,
> >   Alberto
> > _______________________________________________
> > Development mailing list
> > Development at qt-project.org
> > https://lists.qt-project.org/listinfo/development
>
>
> --
> Albert Astals Cid | albert.astals.cid at kdab.com | Software Engineer
> Klarälvdalens Datakonsult AB, a KDAB Group company
> Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
> KDAB - The Qt, C++ and OpenGL Experts
>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> https://lists.qt-project.org/listinfo/development
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20190318/1ad658ec/attachment.html>


More information about the Development mailing list