I have a PySide QMainWindow that I'm running in Nuke. Some widgets used by the application use .ui
files created in Qt Designer.
Until recently, the QMainWindow class was not given a parent. Because of this, when Nuke was minimized or changed focus, the QMainWindow did not minimize or gain focus with it.
To fix that issue, when creating the QMainWindow, I used the QApplication.activeWindow()
method to get an object to feed the QMainWindow as a parent.
parent = QApplication.activeWindow()
window = MyMainWindow(parent)
If I do this, the QMainWindow will minimize and change focus with Nuke. However, when accessing subwidgets of any widget created with .ui
files, it will raise an Exception
Traceback (most recent call last):
...
RuntimeError: Internal C++ object (PySide.QtGui.QPushButton) already deleted.
I'm using a method very similar to this to load the .ui
files onto my QWidget classes
Why are the C++ objects being deleted (garbage-collected)? Why does the behavior change when I specify a parent for the QMainWindow? Is there another way to parent the QMainWindow to Nuke so that in minimizes and focuses correctly or a different way to load the .ui
files without experiencing this garbage collection issue?