[PySide] open/close QMdiArea subwindows

Stefan Champailler schampailler at skynet.be
Tue Feb 26 21:09:44 CET 2013

Well, I've tested my hypothesis (see bug reports) but it didn't solve 
anything... So really looks like a bug....

I've read the Shiboken stuff, but I can't make any sense of it. Should 
read about that...


On 02/25/2013 06:14 PM, Joel B. Mohler wrote:
> On 2/23/2013 4:55 AM, Stefan Champailler wrote:
>> Well, I'm not sure but according to the Qmdiarea doc,
>> addSubwindow does not take ownership of the window.
>> So when the execution path leaves newkid(), w is deleted
>> and then QMdiArea looses it as well...
>> (but I just read the doc, didn't test)
> I don't think that justifies the crash.  If the w widget goes out of
> scope then the widget should have never appeared (being entirely torn
> down by python reference counting on its way out of scope). Either way,
> I've reported it at https://bugreports.qt-project.org/browse/PYSIDE-144
> because I don't think that my app-side python reference issues should
> cause C level segfault crashes.
> Joel
> On 02/21/2013 11:45 PM, Joel B. Mohler wrote:
>>> TL;DR;  QMdiArea claims to take any QWidget in the addSubWindow method.
>>> However, in PySide, this appears to work but it will almost certainly
>>> segfault after many (or few) open/close cycles.
>>> I get a segfault in both windows and linux on the following code. After
>>> opening and closing the window created in "newkid" 4-50 times.  I simply
>>> start the program and press Ctrl+F5, Ctrl+W repeatedly activating the
>>> QAction and using the platform specific close sub-window shortcut.   The
>>> nondescript newkid widget appears and disappears until on some open I
>>> get a segfault.
>>> #!/usr/bin/env python
>>> from PySide import QtCore, QtGui
>>> class MainWin(QtGui.QMainWindow):
>>>         def __init__(self, parent=None):
>>>             super(MainWin, self).__init__(parent)
>>>             self.setCentralWidget(QtGui.QMdiArea())
>>>             self.myaction = QtGui.QAction("add win", self)
>>>             self.myaction.setShortcut("Ctrl+F5")
>>>             self.myaction.triggered.connect(self.newkid)
>>>             self.addAction(self.myaction)
>>>         def newkid(self):
>>>             w = QtGui.QWidget()
>>>             w.setWindowTitle("hi there")
>>>             w.setAttribute(QtCore.Qt.WA_DeleteOnClose)
>>>             self.centralWidget().addSubWindow(w)
>>>             w.showMaximized()
>>> if __name__ == '__main__':
>>>         app = QtGui.QApplication([])
>>>         w = MainWin()
>>>         w.show()
>>>         app.exec_()
>>> Both systems are running PySide 1.1.2 and Qt 4.8.x.
>>> Indeed, I've modified the example to make a QMdiSubWindow rather than a
>>> QWidget and I have yet to have it crash for me after pounding on the F5
>>> & W keys as described above.  I think I have a fix then for the
>>> immediate issue, but I guess this is a bug for the bug tracker as well
>>> since the qmdiarea docs imply this should work.  I think I'm with-in
>>> bounds for the documentation at
>>> http://qt-project.org/doc/qt-4.8/qmdiarea.html#addSubWindow .
>>> Joel
>>> (Side-note:  this is one of the other things that went wrong in my
>>> thread about "RuntimeError:  Failed to connect signal" ... the bug hunt
>>> is wide open I guess and expect I'll find other issues)
>>> _______________________________________________
>>> 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

Timeo Danaos et dona ferentes

More information about the PySide mailing list