Ok, so OverviewEntry::channel() is called for all instances of OverViewEntry?
And each call returned a non-empty list?
Cheers,
_
Ok, so lets summarize:
- Your OverviewEntry QML instances are created
- They display the value of the name property
- They call the channels() getter when assigning to the ListView's model property
- The channels() getters return a correct, non-empty QList<ChannelEntry*>
- The ListView counts are 0
What kind of output do you get when you put this into the ListViews
Qt Code:
onModelChanged: console.log("model for " + modelData.name + " is " + model);To copy to clipboard, switch view to plain text mode
Cheers,
_
I just made the test and this is the output :
- qml: model for OverviewEntry 1 is QVariant(QList<ChannelEntry*>)
- qml: model for OverviewEntry 2 is QVariant(QList<ChannelEntry*>)
- qml: model for OverviewEntry 3 is QVariant(QList<ChannelEntry*>)
- qml: model for OverviewEntry 4 is QVariant(QList<ChannelEntry*>)
- qml: model for OverviewEntry 5 is QVariant(QList<ChannelEntry*>)
- qml: model for OverviewEntry 6 is QVariant(QList<ChannelEntry*>)
Hmm.
You also have
have you tried addingQt Code:
Q_DECLARE_METATYPE(QList<ChannelEntry*>);To copy to clipboard, switch view to plain text mode
Qt Code:
Q_DECLARE_METATYPE(ChannelEntry*);To copy to clipboard, switch view to plain text mode
Cheers,
_
I tried but it doesn't change anything. Even with these two Q_DECLARE_METATYPE commented, it works same way.
But if I comment :
Qt Code:
//Main.cpp ... qmlRegisterType<ChannelEntry>("ChannelEntry", 1, 0, "ChannelEntry"); ...To copy to clipboard, switch view to plain text mode
The app crashed...
Probably because you are now using the same name for the registered type and the QML element type.
Change the second string argument here and maybe also use qmlRegisterUncreatableType()
Cheers,
_
I tried by refactoring my C++ type ChannelEntry into QChannelEntry and setting :
Qt Code:
//Main.cpp ... qmlRegisterType<QChannelEntry>("ChannelEntry", 1, 0, "QChannelEntry"); qmlRegisterUncreatableType<QChannelEntry>("ChannelEntry", 1, 0, "QChannelEntry",""); ...To copy to clipboard, switch view to plain text mode
And the only change is the result of your debug output :
- qml: model for OverviewEntry 1 is QVariant(QList<QChannelEntry*>)
- qml: model for OverviewEntry 2 is QVariant(QList<QChannelEntry*>)
- qml: model for OverviewEntry 3 is QVariant(QList<QChannelEntry*>)
- qml: model for OverviewEntry 4 is QVariant(QList<QChannelEntry*>)
- qml: model for OverviewEntry 5 is QVariant(QList<QChannelEntry*>)
- qml: model for OverviewEntry 6 is QVariant(QList<QChannelEntry*>)
Remark : I also tried by commenting qmlRegisterType or qmlRegisterUncreatableType but with no success
Ok, strange.
Can you try to create a minimal example that can be built and run and shows the problem?
Cheers,
_
Sorry for the late reply but I haven't got the time until now.
I made this little example which build and run but with the same problem.
ListViewExample.zip
I hope it helps to understand the issue.
Ok, this is more complicated than I thought
I found two things that work:
- make the channels property a QList<QObject*>
- Use a QAbstractListModel derived class to provide the channel data
Some other observations:
- main.cpp cannot compile because there is no MainWindow.h, it is mainwindow.h
- this can be written much shorter. Instead of
write thisQt Code:
To copy to clipboard, switch view to plain text mode
Qt Code:
To copy to clipboard, switch view to plain text mode
Cheers,
_
andrioli.n (14th March 2016)
Bookmarks