[Development] QML preprocessor
Albert Astals Cid
albert.astals.cid at kdab.com
Mon Mar 18 09:11:38 CET 2019
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
More information about the Development
mailing list