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: 14
Registered: ‎11-07-2013
My Device: x
My Carrier: y
Accepted Solution

Custom property of datamodel data item

ListView {
            id: idListView
            accessibility.labelledBy: idListView
            objectName: "idListView"
            horizontalAlignment: HorizontalAlignment.Center
            layoutProperties: StackLayoutProperties {
            listItemComponents: ListItemComponent {
                type: "it"
                Container {
                    layout: AbsoluteLayout {
                    topPadding: 4
                    bottomPadding: 4
                    Label {
                        text: ListItemData // <----
                        textStyle {
                            base: SystemDefaults.TextStyles.BodyText
                            fontSize: FontSize.Large
                            fontWeight: FontWeight.Normal
                            color: Color.create ("#ffffffff")


 I made a custom data model for my listview and set it from code. The code above works fine, if QVariant returned from model's data() is a QString. I wanted to return a TableItem(my custom table item) that contains several Q_PROPERTY - ies, and set different property values to different components. My data model:

QVariant TableModel::data(const QVariantList& indexPath) {
	if (indexPath.at(0).toInt() == 0) {
		// first cell (header)
		return QVariant("header");

	int index = indexPath.at(0).toInt();

	TableItem* item= _tableItems.at(index-1);
	QVariant var= QVariant::fromValue(item);

	return var;

 I validated the item before returning it and all properties are fine (has a valid value). All properties return QString and the class has a declared metatype. If I just pass the item like I just wrote, I get "

asset:///table.qml:52: Unable to assign s1::TableItem* to QString", which means TableItem gets passed successfuly. I've tried accessing different properties by calling:

Label {
       text: ListItemData.myPropertyName 


Label {
       text: ListItemData.myPropertyGetter 

 but with no success.


How can I get a property value of an item passed through data() member function of my custom data model? 


Thanks in advance

Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: Custom property of datamodel data item



I can think of two ways to solve your problem...


1. Use a map instead of your object (Variant friendly)

2. Use a GroupDataModel  - as it can store QObject * - not just variant. This post shows this working... http://supportforums.blackberry.com/t5/Native-Development/Update-Sorting-in-ListView/m-p/2629493#M50...



GroupDataModel can do automatic headers. You can also just insert a header into the datamodel - so you don't need to override the data function...





Rob is no longer associated with BlackBerry.
Posts: 14
Registered: ‎11-07-2013
My Device: x
My Carrier: y

Re: Custom property of datamodel data item

Hey there,


Map solved my problem.