Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 77
Registered: ‎05-21-2012
My Device: DA C, Z10 LE, Passport
My Carrier: TIM

Port my QAbstractListModel to Cascades



I would like to port a custom component that uses a QAbstractListModel. As items of this list, I used a QObject.

Here the .h and .cpp I am working on.

In the GroupDataModel docs is stated:


Each item in this model is a QVariantMap or a QObject*.


but I didn't understand well how to use my QObject as content of my list. Or maybe is better to use QListDataModel or something different to expose my list to QML ?


Thanks in advance

Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: Port my QAbstractListModel to Cascades

[ Edited ]

If you are using a ListView, you need to use a subclass of DataModel.

(as per https://developer.blackberry.com/cascades/reference/bb__cascades__listview.html, QML properties: dataModel: bb::cascades:Smiley Very HappyataModel)


Your choices are one of the pre-defined ones, or roll your own.








Posts: 77
Registered: ‎05-21-2012
My Device: DA C, Z10 LE, Passport
My Carrier: TIM

Re: Port my QAbstractListModel to Cascades

Hi Stuart and thanks for your time.

I read the docs and the examples you gave me, but I still have problems to figure out how to achieve my goal with DataModel.

I see for example that I must reimplement

QVariant data (const QVariantList &indexPath)

and this function is meant to comunicate with QML requests as I understand.
Instead QAbstactListModel::data(const QModelIndex &index, int role)  has also the role argument and with this I can know which role of which item its needed.

In my DataModel subclass I have a QList<myQObject *> and each myQObjects has roles like: url, downloadProgress, totalSize etc.
How should I know if the requested indexPath is downloadProgress of the 2nd QList item ?

About my example, I understood that all items of QList<myQObject *> are level 0 and the roles (url, downloadProgress, totalSize etc.) are level 1. Is this correct ?

thanks a lot