[Qt-qml] ListView crashes with more than 256 delegate elements.

Yuvraaj Kelkar yuvraaj at gmail.com
Mon Jan 3 17:36:08 CET 2011


Posting the solution to fix this problem:

> I have a QML List View here:
>
http://code.google.com/p/qgvdial/source/browse/branches/contactsui/qml/ContactsList.qml?r=285
> This list shows contacts from a model which I derive from QSqlQueryModel.
> There are about 800 contacts in the table.
>
> When I scroll down the contacts list, at the point where QML is
> loading the 256th delegate, it spews the output:
> "
> QDeclarativeComponent: Cannot create new component instance before
> completing the previous
> <Unknown File>: QML VisualDataModel: Error creating delgate
> qrc:/ContactsList.qml:105:13: QML Text: Binding loop detected for
> property "text"
> qrc:/ContactsList.qml:95:32767: QML Component: Delegate component must
> be Item type.
> "
>
> And then it segfaults.
>
> If I use qmlviewer with a test ListModel with >1000 contacts, it
> works, but my code does not.
> I think this may be a QML bug, but I am not sure.
> Any help is appreciated.

The solution is to add
while (model->canFetchMore()) { model->fetchMore(); }
after telling the QML view about the model.

The QML ListView was attempting to access the next cached model index.
Since only the first 256 entries had been indexed, the 257th attempt
consistently segfaulted.
With the canFetch,fetchMore loop, the cache is entirely populated and
all is well.


More information about the Qt-qml mailing list