我正在为我的QML ListView提供的QStringList正确显示。现在我想将字符串重新组织成各个部分,但我仍然坚持要提供给section.property的内容!我可以对我的代码进行最小的更改以提供此信息吗? 到目前为止,这是我的代码:
C ++类:
class Foo : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList data READ getData WRITE setData NOTIFY dataChanged)
public:
QStringList getData() const {return m_data;}
void setData(const QStringList &data);
signals:
void dataChanged();
private:
QStringList m_data;
};
的main.cpp
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<Foo>("MyModule", 1, 0, "Foo");
QQuickView view;
view.setSource(QUrl("qrc:/main.qml"));
view.show();
return app.exec();
}
main.qml
import MyModule 1.0
Foo{
id: foo
}
...
ListView {
id: myView
model: foo.data
delegate: Text {text: modelData}
section {
property: what should I write in here ?
}
}