pkl
24th October 2014, 09:36
I have class:
class diagSys : public QObject
{
Q_OBJECT
...
Q_PROPERTY(QList<QObject *> periphList READ periphList NOTIFY sysConfigChanged)
...
periphList is list of objects:
class BriefBlockInfoObject : public QObject
{
Q_OBJECT
Q_PROPERTY(char address READ address WRITE setAddress /*NOTIFY typeChanged*/)
Q_PROPERTY(int id READ id WRITE setId /*NOTIFY textChanged*/)
Q_PROPERTY(QString name READ name WRITE setName /*NOTIFY textChanged*/)
...
I wanna use periphList as model in qml. I export diagSys object:
view->rootContext()->setContextProperty(QLatin1String("DIAG"),
&diag);
From qml I use this:
Repeater {
...
model: DIAG.dispList
...
But It causes an error "ReferenceError: Can't find variable: name/address/id"
But if I export like this:
view->rootContext()->setContextProperty("dispModel",
QVariant::fromValue(diag.dispList()));
and use as model dispModel:
Repeater {
...
model: dispModel
...
it perfectly works.
How can I use as model property value of object, not object itself?
class diagSys : public QObject
{
Q_OBJECT
...
Q_PROPERTY(QList<QObject *> periphList READ periphList NOTIFY sysConfigChanged)
...
periphList is list of objects:
class BriefBlockInfoObject : public QObject
{
Q_OBJECT
Q_PROPERTY(char address READ address WRITE setAddress /*NOTIFY typeChanged*/)
Q_PROPERTY(int id READ id WRITE setId /*NOTIFY textChanged*/)
Q_PROPERTY(QString name READ name WRITE setName /*NOTIFY textChanged*/)
...
I wanna use periphList as model in qml. I export diagSys object:
view->rootContext()->setContextProperty(QLatin1String("DIAG"),
&diag);
From qml I use this:
Repeater {
...
model: DIAG.dispList
...
But It causes an error "ReferenceError: Can't find variable: name/address/id"
But if I export like this:
view->rootContext()->setContextProperty("dispModel",
QVariant::fromValue(diag.dispList()));
and use as model dispModel:
Repeater {
...
model: dispModel
...
it perfectly works.
How can I use as model property value of object, not object itself?