If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

Welcome!

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

Reply
Developer
pepe_ugalde
Posts: 64
Registered: ‎09-10-2012
My Device: Developer
My Carrier: AMX
Accepted Solution

ListItemData.value returns undefined

Hi guys

 

I'm having a weird problem with a ListView.

 

I made a custom Image Loader, based on the Sample

My custom Image Loader class has more variables and more accessors:

    // The accessor methods of the properties
    QVariant image() const;
    QString label() const;
    bool loading() const;

    //-- MY ACCESORS
    QString desc() const;
    QString target() const;
    QString title() const;
    etc...

Also, the sample uses a QListDataModel, and in my app I use a GroupDataModel.

 

The following code works. It is from my earlier version in which I didn't load images from the web:

(lst is a QVariantList loaded from a JSON)

    _dataModel = new GroupDataModel(QStringList() << "porder");
    _dataModel->setParent(this);

    //-- insert the JSON data to model
    _dataModel->insertList(lst);

    //-- make the model flat
    _dataModel->setGrouping(ItemGrouping::None);

    //-- find cascades component of type ListView with an objectName property set to the value 'listView'
    //-- assign data model object (m) to its GUI representation object (list_view)
    if(_listView) _listView->setDataModel(_dataModel);

    _dataModel = new GroupDataModel(QStringList() << "porder");
    _dataModel->setParent(this);

    //-- insert the JSON data to model
    _dataModel->insertList(lst);

    //-- make the model flat
    _dataModel->setGrouping(ItemGrouping::None);

    //-- find cascades component of type ListView with an objectName property set to the value 'listView'
    //-- assign data model object (m) to its GUI representation object (list_view)
    if(_listView) _listView->setDataModel(_dataModel);

 

I attempted to populate the list with my custom class by replacing "_dataModel->insertList(lst);" with this code:

foreach (QVariant vItem, lst) {
    CustomImageLoader *tempCIL = new CustomImageLoader(vItem.toMap(), this);
    _dataModel->insert(tempCIL);
}

 In other words, the same list that was used in the earlier version is now iterated, and CustomImageLoaders are created, each contains data from the list.

 

The result is a list with the correct number of items, but all of them are empty.

 

I have logged the properties of tempCIL and they do contain the same strings from the original list.

 

By populating the list with the Custom class, in my QML code,
ListItemData.title now returns undefined instead of a string.

 

If I print the ListItem's ListItemData, it prints an instance of CustomImageLoader.

 

I made the C++ and QML codes very similar to the Image Loader Sample, and I just can't see where's the mistake.

 

Any hints and pointers are welcome.

 

Please use plain text.
Developer
pepe_ugalde
Posts: 64
Registered: ‎09-10-2012
My Device: Developer
My Carrier: AMX

Re: ListItemData.value returns undefined

DERP DERP

 

I'm not even good at copying

 

I missed the Q_PROPERTYs in the .hpp

 

class CustomImageLoader : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QVariant image READ image NOTIFY imageChanged)
    Q_PROPERTY(QString label READ label NOTIFY labelChanged)

    Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)

    Q_PROPERTY(QString desc READ desc)
    Q_PROPERTY(QString porder READ porder)
    Q_PROPERTY(QString target READ target)
    Q_PROPERTY(QString title READ titulo)
    ...

 

4 hours of pain

Please use plain text.