[PySide] QSelectionModel.currentChanged/selectedChanged signals give troubles

S. Champailler schampailler at skynet.be
Thu Jan 16 13:44:58 CET 2014


Ah, that was a bit fast... This just protects against some nasty stuff when one
*sets* the selection model.
I'm not sure anymore if I do use getSelectionModel without first setting it
myself...
But anyway, this is a grey area for me. The solution that was proposed to you by
the other dude looks fine to me.
Be aware that ownership issues can be difficult to track but one can definitely
live with it(if you search the archive of the mailing list for my mails, you'll
see)

Stefan

> Le 16 janvier 2014 à 13:35, "S. Champailler" <schampailler at skynet.be> a
> écrit :
>
>
> When you get the selection model you have to take ownership of it. Therefore
> you
> do have to keep a reference to it in your own code. Qt's doc gives some
> information about it...
>
> Now I remember that there was a bug with that, where the ownership was not
> correctly passed to the caller. This bug came and go and came again. Right
> now,
> I've redefined QTableView like this :
>
> from PySide.QtGui import QTableView
>
> class QTableView(QTableView):
>     def __init__(self,parent=None):
>         super(QTableView,self).__init__(parent)
>         self._selection_model = None
>
>     def setModel(self,model):
>         super(QTableView,self).setModel(model)
>         self._selection_model = super(QTableView,self).selectionModel()
>
>     def selectionModel(self):
>         return self._selection_model
>
>
> and so far it has worked perfectly (I have an application in production since
> 2
> months, used 8 hours a day by 4-5 persons that makes extensive use of
> selection
> models)
>
> Stefan
>
>
>
> > Le 16 janvier 2014 à 12:53, Andy Kittner <andy.kittner at gmail.com> a écrit :
> >
> >
> > On 16.01.2014 11:50, Alexey Vihorev wrote:
> > > Hi!
> > >
> > > I’ve got a problem trying to connect currentChanged/selectedChanged
> > > signals
> > > to anything. The code:
> > I vaguely remember having a similar problem once (it's ages ago so
> > things might have changed).
> > After some debugging I found that the object providing the slot was garbage
> > collected before the connection was made resulting in the crash.
> >
> >
> > Can you try changing this
> >
> > >         self.view.selectionModel().currentChanged.connect(self.handler)
> >
> > To the following:
> >
> >           selection_model = self.view.selectionModel()
> >           selection_model.currentChanged.connect(self.handler)
> >
> > And see if that helps?
> >
> > Regards,
> > Andy
> > _______________________________________________
> > PySide mailing list
> > PySide at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/pyside
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside



More information about the PySide mailing list