[PySide] QSortFilterProxyModel and QListView - indexWidget pointer get deleted when filtering

Matthieu Cadet matthieu.cadet at gmail.com
Mon Aug 11 11:27:03 CEST 2014


Hi

Thanks for your help guys... I'm still stuck with this bug...

Here is a simplified version of the code:
https://gist.github.com/maty974/66e29df303d1f1825a53

Instead of using a QLabel to show text I paint the text value in the
painter of the widget.

But after made thoses changes, I've discover that each CustomItemWidget()
widget get the "QEvent.Type.DeferredDelete" event after filtering with the
Proxy model...

So now after filtering the model, each indexWidget() get deleted and I
don't get any error, and what is
visible after filtering is the QtGui.QStandardItem and its DisplayRole...

I've also check in the C++ source code of Qt for QAbstractItemView to see
how the indexWidget is set:
https://qt.gitorious.org/qt/qt/source/bfa0be8a1bf68200f1ba98888deff4a9215ee066:src/gui/itemviews/qabstractitemview.cpp#L3087-3088

and I don't really understand when this part of code happen:

    if (QWidget *oldWidget = indexWidget(index)) {
        d->persistent.remove(oldWidget);
        d->removeEditor(oldWidget);
        oldWidget->deleteLater();
    }


Anyway I'll try to investigate more into this :)


Thanks for testing this for me ;)


Matthieu



On Sun, Aug 10, 2014 at 9:15 AM, Stefan Champailler <schampailler at skynet.be>
wrote:

> Yep, Jesus idea seems right. PySide (an dPyQt4) I guess being C++
> bindings, one has to be careful with pointers. This is quite misleading
> sometimes. Fortunatelemy, with times, one learns the safe design patterns,
> so it(s not much of a problem.
>
> By the way, it's quite surprising to see a reference to a view widget
> (QLabel) in a model item. I don't say it leads to bug nor that it is plain
> wrong, but it's just not very MVC (model view ocntroller pattern)
>
> stF
>
>
> On Sun, 10 Aug 2014 00:26:30 +0200
> Jesus <ea7dfh at ea7dfh.com> wrote:
>
> > Hi
> >
> > I'm not an expert programmer in python nor pyside by far, but I've made
> > a test using pyqt4 with your code and the error is the same.
> >
> > This is the kind of bug when an object loss its reference to itself
> > inside a class. So I would check if the label item still has a parent
> > when it is filtered (or deleted?) by the model. I may be wrong, of
> > course, so please be gentle.
> >
> > Regards,
> >
> > Jesus
> >
> > El 09/08/14 23:28, Stefan Champailler escribió:
> > > I've removed some useless code but the issue still is there...
> > >
> > > really sounds like a bug...
> > >
> > > stF
> > >
> > >
> > > On Sat, 9 Aug 2014 23:10:33 +0200
> > > Stefan Champailler <schampailler at skynet.be> wrote:
> > >
> > >> Hi MAtthieu,
> > >>
> > >> I can reproduce your bug
> > >>
> > >> Could you try to make a simpler version of your code ? Sometimes, it
> helps to sort out other causes of error (I had my share of dangling pointer
> with PySide...)
> > >>
> > >> Stefan
> > >>
> > >>
> > >>
> > >> On Fri, 8 Aug 2014 12:06:58 +0200
> > >> Matthieu Cadet <matthieu.cadet at gmail.com> wrote:
> > >>
> > >>> Hi
> > >>>
> > >>> As I didn't get answer yet, I've also post a question on
> StackOverflow
> > >>>
> > >>>
> http://stackoverflow.com/questions/24995936/pyside-qsortfilterproxymodel-and-qlistview-indexwidget-pointer-get-deleted-w
> > >>>
> > >>> Someone has test the code on Windows 7 with PySide 1.2.2 and Python
> 3.3 and
> > >>> says it works for him without RuntimeError message....
> > >>>
> > >>> I'm still trying to find a solution to this problem :P
> > >>>
> > >>>
> > >>>
> > >>> On Mon, Jul 28, 2014 at 2:26 PM, Matthieu Cadet <
> matthieu.cadet at gmail.com>
> > >>> wrote:
> > >>>
> > >>>> Hi PySide guru's
> > >>>>
> > >>>> I've a problem with a custom QListView I'm trying to make, here the
> > >>>> problem:
> > >>>>
> > >>>> I'm using QListView to show a list of QWidget object by using
> > >>>> QListView.setIndexWidget(),
> > >>>> this works pretty fine, but now I want to filter the item model by
> > >>>> using QSortFilterProxyModel()
> > >>>> with .setFilterWildcard() it is not working very well because the
> second
> > >>>> time the model is filtered
> > >>>> I got error like this :
> > >>>>
> > >>>> *RuntimeError: Internal C++ object (PySide.QtGui.QLabel) already
> deleted.*
> > >>>>
> > >>>> Without using filtering and QSortFilterProxyModel everything works
> fine,
> > >>>> but it seems I'm missing
> > >>>> something with the filtering operation, the indexWidget() is
> deleted when
> > >>>> using filtering :(
> > >>>>
> > >>>> here a sample code where you can reproduce the bug, when list view
> is
> > >>>> shown, hit 1,2 or 3 keyboard
> > >>>> key to activate filtering ( Backspace to set filtering empty to
> show all
> > >>>> items )
> > >>>>
> > >>>> *https://gist.github.com/66e29df303d1f1825a53.git
> > >>>> <https://gist.github.com/66e29df303d1f1825a53.git>*
> > >>>>
> > >>>>
> > >>>> Can someone please help me on this? is this a known bug ? or I'm
> doing it
> > >>>> completely wrong :P
> > >>>>
> > >>>> Thanks in advance for your help.
> > >>>>
> > >>>> --
> > >>>> Matthieu Cadet
> >
> >
> >
> > --
> > Jesus Guardon
> > _______________________________________________
> > PySide mailing list
> > PySide at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/pyside
>
>
> --
> Timeo Danaos et dona ferentes
> Twitter : @Arakowa1
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
>



-- 
Matthieu Cadet
Compositor Artist & TD,
nWave Digital
matthieu.cadet at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20140811/8e93d507/attachment.html>


More information about the PySide mailing list