[PySide] Strange behavior of QML ListView and QAbstractListModel

43 views
Skip to first unread message

Vláďa

unread,
Feb 24, 2011, 4:20:51 AM2/24/11
to pys...@lists.openbossa.org
Hi list,

I'm having problems with replacing content of QAbstractListModel, which
is showed in a QML UI.

I checked my code many times, but I can't find any bugs there. So I
created a simple demo, which shows the problem. Please check the
attachment, it contains a PySide application, which shows a QML window.
The window contains a list with 5 items and 2 buttons - "all" and
"reduce". Button "all" fills the list with all 5 items, button "reduce"
shows only first 2. You can see some debug messages in console.

Now try to use the 2 buttons and you can see that it behaves totally
wrong. The good thing is that it behaves equally every time, which
should make it easier to debug. For example try to hit "reduce" two
times. The first time it works OK, but the second time you'll see only
empty delegates and error messages in console. I think the most
important information is that QML requests from QAbstractListModel item
with index -1, which of course doesn't exist. Now try to move the list
up or down so that the delegates are moved away from the window. And
when the list returns, the delegates are suddenly showed correctly.

I hope I described the behavior clearly. Anyway please check my example
and you can see it yourself. I hope the code is self explaining, if not,
please let me know and I'll add some comments to it.

Best regards,
Vladimir

llistmodel_test.7z

Thomas Perl

unread,
Feb 24, 2011, 5:48:51 AM2/24/11
to Vláďa, pys...@lists.openbossa.org
Hi Vláďa,

2011/2/24 Vláďa <vla...@atlas.cz>:
> [...] I think the most important information is that QML


> requests from QAbstractListModel item with index -1, which of course doesn't
> exist.

In that case, your model should return None (in C++ one would return
an empty/invalid(?) QVariant.

HTH.
Thomas
_______________________________________________
PySide mailing list
PyS...@lists.openbossa.org
http://lists.openbossa.org/listinfo/pyside

Vláďa

unread,
Feb 24, 2011, 6:01:07 AM2/24/11
to Thomas Perl, pys...@lists.openbossa.org
Hi Thomas,

thank you for the answer. I could change my code to implement this. But
the QML UI should never request data for item with index -1. Such item
doesn't exist. There should be two items with indexes 0 and 1.

So even if I changed my code so that it returns None, I would only
eliminate the error message, but it wouldn't solve my problem. I will
still get empty delegates.

Regards,
Vladimir

Dne 24.2.2011 11:48, Thomas Perl napsal(a):

Reply all
Reply to author
Forward
0 new messages