Model Roles with children C++ classes
-
Hi,
I'm currently pototyping a kind of AVOD portal in QML with a Qt based C++ backend for the media catalog.
I basically have a kind of MediaObject base c++ class with children classes for MediaMovie, MediaAudio (mp3, albums) and MediaStream.I've planed to implement a flickable object with each media cover, and as soon as a media is selected, display the related media data, depending of its type (movie, audio or stream).
Until then, I've never faced this issue, I used to have a model with roles accessed in the delegate.
In that particular case, roles might depend on the type of the media. In C++, this case might be fixes with the visitor pattern.
But how could it be handled with QML ?Any suggestion is welcome.
Cheers.
K.
-
Hi,
You may have missed the Qt Quick model view chapter in Qt's documentation. I think it should contain the information you are looking for.
-
You would like something like a dynamic delegate to match the underlying object ?
How big are the differences between your media classes ?
-
If you want to return a QAbstractList/ItemModel you can do that as a role:
QVariant value; ... case modelRole: value = QVariant::fromValue(m_somemodel); // object based upon QObject* or QAbstractItemModel* or similar break;
Edit: This is in the data() function call and value is returned.
-
@fcarney said in Model Roles with children C++ classes:
@Karim said in Model Roles with children C++ classes:
But how could it be handled with QML ?
DelegateChooser
Sorry for my late reply, I was sick off.
Thanks for your feedback, I'll try your suggestion and let you know...but it makes sense at first glance.