From 83533ddc5d89feb046863b4dacc86be3967e4a6b Mon Sep 17 00:00:00 2001 From: renatofilho Date: Wed, 6 Oct 2010 18:54:51 -0300 Subject: Used proxy object in QUiLoader loaded widget to avoid cyclic reference. Reviewer: Hugo Parente Lima Luciano Wolf --- PySide/QtUiTools/glue/uitools_loadui.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'PySide/QtUiTools') diff --git a/PySide/QtUiTools/glue/uitools_loadui.h b/PySide/QtUiTools/glue/uitools_loadui.h index bce1367c1..5729b5f30 100644 --- a/PySide/QtUiTools/glue/uitools_loadui.h +++ b/PySide/QtUiTools/glue/uitools_loadui.h @@ -18,7 +18,7 @@ _populate_parent(PyObject* pyParent, QObject *parent) bool has_attr = PyObject_HasAttrString(pyParent, qPrintable(name)); Shiboken::AutoDecRef pyChild(Shiboken::Converter::toPython(child)); if (!has_attr) - PyObject_SetAttrString(pyParent, qPrintable(name), pyChild); + PyObject_SetAttrString(pyParent, qPrintable(name), PyWeakref_NewProxy(pyChild, 0)); Shiboken::setParent(pyParent, pyChild); _populate_parent(pyChild, qobject_cast(child)); @@ -53,14 +53,17 @@ quiloader_load_ui(QUiLoader* self, const QString &ui_file, QWidget *parent) QWidget* w = self->load(&fd, parent); fd.close(); if (w != 0) { - PyObject* pyParent = Shiboken::Converter::toPython(w); + QObject *_parent = parent; + if (!_parent) + _parent = w; + Shiboken::AutoDecRef pyParent(Shiboken::Converter::toPython(_parent)); if (parent && parent->layout()) parent->layout()->deleteLater(); - _populate_parent(pyParent, w); + _populate_parent(pyParent, _parent); - return pyParent; + return Shiboken::Converter::toPython(w); } } PyErr_SetString(PyExc_RuntimeError, "Unable to open ui file"); -- cgit v1.2.3