I have a Q_PROPERTY
of type QList<QString>
in a c++
class that is not being shown in QML. The class looks like this:
class FooView : public QQuickItem
{
Q_OBJECT;
Q_PROPERTY(QList<QString> myStrings READ myStrings NOTIFY myStringsChanged);
private:
QList<QString> m_strings;
public:
FooView(QQuickItem * parent) : QQuickItem(parent), m_strings() {
m_strings << "String one" << "String two";
}
QList<QString> myStrings() const {
return m_strings;
}
signals:
void myStringsChanged();
};
The above class is registered as a QML type using qmlRegisterType
. I try to use the property as a model to a ListView
like so:
FooView {
id: 'foo'
ListView {
anchors.fill: parent
model: foo.myStrings
delegate: Text {
text: "Hi" // to be replaced with foo.myStrings[index]
}
}
}
Can you not use QList<QString>
's as models? I thought you could since it was listed as a simple list type.
m_strings()
? in the constructor. – Phiberm_string()
override yourm_strings << "String one" << "String two";
so your are using empty list – Phiberm_strings << "String one" << "String two";
it runs afterm_string()
, althoughm_string()
is unnecessary because a list is empty by default – eyllanesc