python - PySide widgets using .ui files being garbage-collected unexpectedly -


i have pyside qmainwindow i'm running in nuke. widgets used application use .ui files created in qt designer.

until recently, qmainwindow class not given parent. because of this, when nuke minimized or changed focus, qmainwindow did not minimize or gain focus it.

to fix issue, when creating qmainwindow, used qapplication.activewindow() method object feed qmainwindow parent.

parent = qapplication.activewindow() window = mymainwindow(parent) 

if this, qmainwindow minimize , change focus nuke. however, when accessing subwidgets of widget created .ui files, raise exception

traceback (most recent call last):     ... runtimeerror: internal c++ object (pyside.qtgui.qpushbutton) deleted. 

i'm using method very similar this load .ui files onto qwidget classes

why c++ objects being deleted (garbage-collected)? why behavior change when specify parent qmainwindow? there way parent qmainwindow nuke in minimizes , focuses correctly or different way load .ui files without experiencing garbage collection issue?

the problem occurs when 1 of parent widgets gets garbage-collected because no python object reference exists. instance:

def create_window():     parent = qapplication.activewindow()     window = mymainwindow(parent)     return window 

when function returns, parent object goes out of scope , c++ pyobject represents garbage collected. strange problem widgets created .ui files. solution keep reference parent objects. i'm using global variable store references them.

gc_protect = []  def create_window():     parent = qapplication.activewindow()     gc_protect.append(parent)     window = mymainwindow(parent)     return window 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -