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 
<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@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to