May I ask a few questions about implementing QML models in C++? Apologies if I sound uninformed.

1) When a model is specified on the QML side, e.g. in

    ComboBox {
    model xxxxx;

and that model is supplied by the C++ code, does the object returned by C++ have to a model object, e.g. a QStringListModel or a QAbstractListModel? Or could it be a simple QStringList in the case of a simple ListView or ComboBox?
    I suspect the former applies.

2) When the model is returned from C++ to QML, must this be performed by a C++ object that inherits from such a model class (e.g. QAbstractListModel) or could it be any class (i.e. inheriting from an arbitrary base class) that has an extractor method returning an appropriate model?

3) Related to the above, within the Download-from-dc context, is the model used by the QML is dependent on the specific standard built-in methods provided by one of the standard model classes (let's say QAbstractListModel) or can one implement an arbitrary extractor method that returns a model (e.g a QStringListModel). To me it looks like the latter is the case because QAbstracListModel does not have a standard built-in method that returns the complete list.

4) Within the existing main.qml, selecting "Show GPS fixes" activates the C++ qmlManager.populateGpsData() method that, in turn, activates GpsListModel::instance()->update. The appropriate (now updated) model is m_instance, returned by GpsListModel::instance(). [So syntactically the :: operator has priority over the -> operator, because instance()->update() does not make sense.]
Is my understanding correct here?
Now, the actual display of GPS data is done in gpsList.qml, using gpsModel as a model and formatted by gpsDelegate. But I cannot link gpsModel back to main.qml, QMLManager or to GpsListModel. Where is the link made between gpsModel in gpsList.qml and the underlying C++ code? As discussed before I would have used ctxt->setContextProperty("gpsModel", QVariant::fromValue(gpsQStringList)) but this is clearly not the case here.

5) If I understand it correctly, one can let DownloadManager inherit from QAbstractListModel, then let DownloadManager have two extractor methods, getVendorModel() and getProductModel() that each return an appropriate and populated model, callable from QML. Does this make sense at all?

I hope my questions are clear, and thank you so much for your time in answering.
Kind regards,
willem







_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to