[PyQt] QMainWindow bug?
Hans-Peter Jansen
hpj at urpla.net
Sat Jan 22 14:16:59 GMT 2011
On Friday 21 January 2011, 10:21:11 Mailing List SVR wrote:
> Hi Erik,
>
> attacched is a small sample of what I'm doing in my app, I have a
> dialog that require some time to open, to speed up the things I store
> it in a global object and use this global object to reopen the
> dialog,
>
> this seems to work, I'm reusing the same dialog from different
> central widget, some times (I'm unable to reproduce) I see in the
> logs:
>
> RuntimeError: underlying C/C++ object has been deleted
>
> so I added a try except when I open the dialog, until today noone
> reported segfault, what do you think about this usage?
It's ugly as sin and you're playing with fire by reparenting stuff, etc.
Why can't you use a pattern like:
class AppGlobal(object):
global_dlg=None
class TestWidget(QtGui.QWidget):
def onClick(self):
if app_global.global_dlg is None:
app_global.global_dlg = TestDialog(self)
app_global.global_dlg.exec_()
given, TestWidget is some object, that doesn't go out of scope. Don't
play games with reparenting, because a None parent might trick Qt into
freeing up its resources. At least, it is very intrusive for no good
reasons. If you really want to reuse such a dialog with different
parents, I would refactor the time consuming stuff into its own class,
and access it from two different dialog instances, that can be created
with the above pattern just fine.
Pete
> thanks
> Nicola
>
> Il giorno ven, 21/01/2011 alle 08.47 +0100, Erik Janssens ha scritto:
> > Hi,
> >
> > I wrote some general documentation around these
> > issues, with regard to Camelot development, but
> > it might be of use to others as well :
> >
> > http://downloads.conceptive.be/downloads/camelot/doc/sphinx/build/a
> >dvanced/development.html
> >
> > all remarks/corrections are welcome.
> >
> > Regards,
> >
> > Erik
> >
> > On Thu, 2011-01-20 at 10:22 +0100, Mailing List SVR wrote:
> > > Ok, in a my pyqt app (I'm still using pyqt-4.7.x), I have a
> > > dialog that require much time to open so I keep a reference to it
> > > in a app global variable and I use this reference to reopen the
> > > dialog after the first time. This seems to work and the dialog
> > > open much quicker, however in some undeterminated cases I get:
> > >
> > > RuntimeError: underlying C/C++ object has been deleted
> > >
> > > when I get this error I recreate the dialog and update the global
> > > reference,
> > >
> > > can you please explain the right way to keep a reference in
> > > python to a qt object?
> > >
> > > thanks
> > > NIcola
> > >
> > > Il giorno mer, 19/01/2011 alle 23.47 +0100, Erik Janssens ha
scritto:
> > > > there was a change in sip/pyqt from 4.8.1 to 4.8.2 regarding
> > > > the detection of objects deleted by qt but still referenced in
> > > > python (which is the case here). in 4.8.1 sip/pyqt tried to
> > > > detect this to avoid segfaults. this detection however brought
> > > > other issues with it, therefor the detection was turned off
> > > > again in 4.8.2
> > > >
> > > > the solution is not to keep references in python of objects
> > > > owned by qt when they might get deleted.
> > > >
> > > > On Wed, Jan 19, 2011 at 12:36 PM, Mailing List SVR
> > > >
> > > > <lists at svrinformatica.it> wrote:
> > > > > I can confirm the segfault:
> > > > >
> > > > > - linux, kernel 2.6.36
> > > > > - python 2.7.1
> > > > > - pyqt 4.8.2
> > > > > - qt 4.7.1
> > > > >
> > > > > works fine with PySide,
> > > > >
> > > > > Nicola
> > > > >
> > > > > Il giorno mer, 19/01/2011 alle 08.36 +0100, Vicent Mas ha
scritto:
> > > > >> 2011/1/18 Nick Gaens <mail at nickgaens.com>:
> > > > >> > - Win7 64bit
> > > > >> > - Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC
> > > > >> > v.1500 32 bit (Intel)] on win32
> > > > >> > - Qt v4.7.0
> > > > >> > - PyQt GPL v4.8.1 for Python v2.6
> > > > >> > Result: no crashes, works like a charm..
> > > > >>
> > > > >> Hi,
> > > > >>
> > > > >> I get the crash also on Windows Vista 32bit (again Python
> > > > >> 2.6 and PyQt 4.8.2)
> > > > >>
> > > > >> Vicent
> > > > >
> > > > > _______________________________________________
> > > > > PyQt mailing list PyQt at riverbankcomputing.com
> > > > > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> > > >
> > > > _______________________________________________
> > > > PyQt mailing list PyQt at riverbankcomputing.com
> > > > http://www.riverbankcomputing.com/mailman/listinfo/pyqt
More information about the PyQt
mailing list