I have class:
{
Q_OBJECT
...
Q_PROPERTY(QList<QObject *> periphList READ periphList NOTIFY sysConfigChanged)
...
class diagSys : public QObject
{
Q_OBJECT
...
Q_PROPERTY(QList<QObject *> periphList READ periphList NOTIFY sysConfigChanged)
...
To copy to clipboard, switch view to plain text mode
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*/) ...
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*/)
...
To copy to clipboard, switch view to plain text mode
I wanna use periphList as model in qml. I export diagSys object:
&diag);
view->rootContext()->setContextProperty(QLatin1String("DIAG"),
&diag);
To copy to clipboard, switch view to plain text mode
From qml I use this:
Repeater {
...
model: DIAG.dispList
...
Repeater {
...
model: DIAG.dispList
...
To copy to clipboard, switch view to plain text mode
But It causes an error "ReferenceError: Can't find variable: name/address/id"
But if I export like this:
view->rootContext()->setContextProperty("dispModel",
view->rootContext()->setContextProperty("dispModel",
QVariant::fromValue(diag.dispList()));
To copy to clipboard, switch view to plain text mode
and use as model dispModel:
Repeater {
...
model: dispModel
...
Repeater {
...
model: dispModel
...
To copy to clipboard, switch view to plain text mode
it perfectly works.
How can I use as model property value of object, not object itself?
Bookmarks