[Interest] QAbstractItemModel and Qml - modelData is null
Pierre-Yves Siret
py.siret at gmail.com
Mon Oct 16 23:16:22 CEST 2017
2017-10-16 20:11 GMT+02:00 Nuno Santos <nunosantos at imaginando.pt>:
> Hi,
>
> I have for the first time defined a QAbstractItemModel to use on Qml
> because I needed to have a filtered version of this model
> using QSortFilterProxyModel.
>
> I have the documentation here -> http://doc.qt.io/archives/
> qt-5.5/qtquick-modelviewsdata-cppmodels.html and followed the example
> given. I have defined the following roles:
>
> enum PatchRoles {
> IdRole = Qt::UserRole + 1,
> NameRole,
> ModifiedRole,
> TagsRole,
> ModelDataRole
> };
>
> And then under data retrieval method:
>
> QVariant IPatchManagerModel::data(const QModelIndex & index, int role)
> const
> {
> if (index.row() < 0 || index.row() >= _patches.count())
> return QVariant();
>
> IPatch* patch = _patches.at(index.row());
>
> if (role == IdRole)
> return patch->id();
> else if (role == NameRole)
> return patch->nameLabel();
> else if (role == ModifiedRole)
> return patch->modified();
> else if (role == TagsRole)
> return patch->tags();
> else if (role == ModelDataRole)
> * return qVariantFromValue((void *) patch);*
>
> return QVariant();
> }
>
> Every role works except modelData, whenever I try to access it it gives me
> null on the Qml side.
>
> Does anyone knows what am I doing wrong?
>
> Thanks,
>
> Regards,
>
> Nuno
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
I'm gonna go out on a limb and say that the QML engine can't deal with
void* type.
What type is patch? Put it in the variant as a QObject* instead if you can.
Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20171016/21d28da1/attachment.html>
More information about the Interest
mailing list