[Development] Question about Qt's future

Roland Winklmeier roland.m.winklmeier at gmail.com
Mon Apr 21 14:52:25 CEST 2014


>>
>> - Our application has a huge framework of value classes. They cannot (or
>> at least it does not make sense to) derive from QObject for several
>> reasons. But subclassing QObject is the requirement to access data from
>> C++ in QML. So we had our framework of well designed value classes and
>> cannot use them in QML. There were evaluations to create QObject
>> wrappers, but no nice solution. So no support for value classes is
>> probably a show stopper for many projects. With Widgets we were able to
>> use them easily.
> 
> Hmm, I’m not sure what you mean by value classes.  Do you mean literally data models?  You don’t need to move QObjects across to QML if you are just sending data for display in the UI.  We have lots of complicated data types that we simply save in QVariantMaps, and they show up as javascript objects in QML. You may not have this flexibility, but as the application designer on our project I don’t allow anyone to put new classes into QML from c++ unless they directly drive a viewable element, because that contaminates the view layer with business logic, following the MVC pattern.  I wouldn’t allow that with widgets either.
> 

The term value classes is due to history reasons in our project. We
started creating classes to handle physical values. Hence the name.
Some of them are data models representing entities (e.g. aircrafts) and
also abstract items (e.g. altitude, callsign, flightplan). All these
classes have an advanced API and logic written in C++, for example
CAltitude has complex API methods to get the value in different units.
We also use them as a property/value for example to assign it to an
aircraft: setAltitude(const CAltitude &altitude).
If I want to access this methods from QML I would have to derive them
from QObject and register it in the QML context.
I remember QVariantMaps were also discussed. I cannot remember exactly
why we finally did not use them. But I guess QVariantMaps are only for
easy types.
Maybe there is a way to do it and I have overlooked it. I can remember
some discussion in this list
(http://lists.qt-project.org/pipermail/interest/2013-October/009202.html) and
also in IRC saying, some kind of value class support is planned.
For the time being it was a lot easier to call a c++ method
getAltitude(AltitudeUnit unit) from QtWidgets than QML :)


---
Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus Schutz ist aktiv.
http://www.avast.com




More information about the Development mailing list