In our application, we need to display a GridView wich contains some elements of custom type OverviewEntry and in these elements, we have a QList of element of custom type ChannelEntry.
Some code is more usefull than a long description so, please found the related code (simplified, of course) :
//Main.cpp
...
m_viewer = new QQuickView();
...
QList<ChannelEntry *> channels;
for (int i=0; i<5; i++) {
for (int j=0; j<4; j++) {
channels.append(new ChannelEntry("foo"));
}
m_overviewList.append(new OverviewEntry("bar", channels));
}
...
QQmlContext *ctxt = m_viewer->rootContext();
ctxt
->setContextProperty
("overviewModel",
QVariant::fromValue(m_overviewList
));
...
//Main.cpp
...
m_viewer = new QQuickView();
...
QList<ChannelEntry *> channels;
for (int i=0; i<5; i++) {
for (int j=0; j<4; j++) {
channels.append(new ChannelEntry("foo"));
}
m_overviewList.append(new OverviewEntry("bar", channels));
}
...
QQmlContext *ctxt = m_viewer->rootContext();
ctxt->setContextProperty("overviewModel", QVariant::fromValue(m_overviewList));
...
To copy to clipboard, switch view to plain text mode
//OverviewEntry.h
class OverviewEntry
: public QObject{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged
) ...
Q_PROPERTY(QList<ChannelEntry> channels READ channels WRITE setChannels NOTIFY channelsChanged)
...
QList<ChannelEntry *> m_channels;
};
Q_DECLARE_METATYPE(QList<ChannelEntry>)
//OverviewEntry.h
class OverviewEntry : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
...
Q_PROPERTY(QList<ChannelEntry> channels READ channels WRITE setChannels NOTIFY channelsChanged)
...
QString m_name;
QList<ChannelEntry *> m_channels;
};
Q_DECLARE_METATYPE(QList<ChannelEntry>)
To copy to clipboard, switch view to plain text mode
//ChannelEntry.h
class ChannelEntry
: public QObject{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged
) ...
};
//ChannelEntry.h
class ChannelEntry : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
...
QString m_name;
};
To copy to clipboard, switch view to plain text mode
//Main.qml
...
GridView {
model: overviewModel
delegate : OverviewEntry {}
}
...
//Main.qml
...
GridView {
model: overviewModel
delegate : OverviewEntry {}
}
...
To copy to clipboard, switch view to plain text mode
//OverviewEntry.qml
...
Text{
text: modelData.name
}
...
ListView {
model: modelData.channels
delegate : ChannelEntry {}
}
...
//OverviewEntry.qml
...
Text{
text: modelData.name
}
...
ListView {
model: modelData.channels
delegate : ChannelEntry {}
}
...
To copy to clipboard, switch view to plain text mode
//ChannelEntry.qml
...
Text{
text: modelData.name
}
...
//ChannelEntry.qml
...
Text{
text: modelData.name
}
...
To copy to clipboard, switch view to plain text mode
My GridView is well populated but my ListView remains empty... Even after 2-3 days of trying different approach...
So what am I missing ? Anyone has a clue, please ?
Bookmarks