Can't access model variable from delegate
-
Hi everyone,
playing with qml a bit I came to another problem i can't solve by myself. My data should be presented via a listview component, but I'm not able to access the variables from within the delegate. I declared the datamodel like this:
@Q_PROPERTY(QVariant dataModel READ getDataModel NOTIFY dataModelChange)@and the getter looks like this:
@ QList<QObject*> data;data.append(new QmlDataObject("first", "test1"));
data.append(new QmlDataObject("second", "test2"));
data.append(new QmlDataObject("third", "test3"));return (QVariant::fromValue(data));@
QmlDataObject:
@class QmlDataObject : public QObject
{
Q_OBJECTQ_PROPERTY(QString name READ getName); Q_PROPERTY(QVariant value READ getValue);
public:
QmlDataObject(QString name, QVariant value);
virtual ~QmlDataObject();
void setValue(QVariant value);signals:
void nameChanged(QString);
void valueChanged(QVariant);private:
QString name;
QVariant value;
QString getName() const { return (name);}
QVariant getValue() const { return (value);}};@
qml:
@ Component {
id: listDelegate
Item {
id: wrapper
height: 26
Column {
Text {
id: mytext
color: "#FFFFFF"
font.pixelSize: 12
font.weight: Font.Bold
height: 16
text: model.name
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
Text {
id: mytext2
color: "#FFFFFF"
font.pixelSize: 10
font.weight: Font.Normal
height: 10
text: model.value
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
}
}
}@The datamodel seems to be accessable, as I'm getting 3 times
"Unable to assign [undefined] to QString text
Unable to assign [undefined] to QString text".Regards
Markus -
Since i remember you have to use for example text: name instead of text: model.name .
-
I have already tried with this result:
3x
ReferenceError: Can't find variable: value
ReferenceError: Can't find variable: name