12-05-2012 04:43 PM
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.
Solved! Go to Solution.
12-05-2012 05:26 PM
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