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

New Developer
Posts: 16
Registered: ‎12-16-2010
My Device: Not Specified
Accepted Solution

arraydatamodel with QvariantList


I have an  arraydatamodel added to a list.

I want to populate the ArrayDataModel from a database  datasource

My datamodel returns a QVariantList wich seems that it  isn't supported by the arraydatamodel.


How can I solve this in QML and add in the objects contained by the QVariantList ?


PS:I don't want to use the GroupedDataModel

                            attachedObjects: [
                               DataSource {
                                    id: modelsDataSource
                                    source: "sql/lists.db"
                                    query: "SELECT * FROM cars ORDER BY id "
                                    property int loadCounter: 0
                                    onDataLoaded: {
                                        if (data.length > 0) {

                                        arrayModel.insert(data); <------------ Here is the problem,data is a  QVariantList

Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: arraydatamodel with QvariantList



for(var i = 0; i < data.length; ++i)


Andrey Fidrya, @zmeyc on twitter
New Developer
Posts: 16
Registered: ‎12-16-2010
My Device: Not Specified

Re: arraydatamodel with QvariantList

I also found that you can use the GroupedDataModel in the same way as an ArrayModel just don't declare grouping and sortingKeys in your custom model declaring them even if with no values : ItemGrouping.None  sortingKeys: ;   doesn't work how expected

Posts: 137
Registered: ‎10-26-2010
My Device: Bold 9900 + PlayBook
My Carrier: Rogers

Re: arraydatamodel with QvariantList

[ Edited ]

The insert function takes two parameters, an integer for where to insert and the data to be inserted. I believe that's why your original code failed. You should be able to just do arrayModel.append(data) without looping through it, https://developer.blackberry.com/cascades/reference/bb__cascades__arraydatamodel.html#append indicates that it can take a QVariantList.

Taylor Byrnes