Used proxy object in QUiLoader loaded widget to avoid cyclic reference.
Reviewer: Hugo Parente Lima <hugo.pl@gmail.com>
Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
e75b82fdf6
commit
83533ddc5d
1 changed files with 7 additions and 4 deletions
|
|
@ -18,7 +18,7 @@ _populate_parent(PyObject* pyParent, QObject *parent)
|
||||||
bool has_attr = PyObject_HasAttrString(pyParent, qPrintable(name));
|
bool has_attr = PyObject_HasAttrString(pyParent, qPrintable(name));
|
||||||
Shiboken::AutoDecRef pyChild(Shiboken::Converter<QObject*>::toPython(child));
|
Shiboken::AutoDecRef pyChild(Shiboken::Converter<QObject*>::toPython(child));
|
||||||
if (!has_attr)
|
if (!has_attr)
|
||||||
PyObject_SetAttrString(pyParent, qPrintable(name), pyChild);
|
PyObject_SetAttrString(pyParent, qPrintable(name), PyWeakref_NewProxy(pyChild, 0));
|
||||||
|
|
||||||
Shiboken::setParent(pyParent, pyChild);
|
Shiboken::setParent(pyParent, pyChild);
|
||||||
_populate_parent(pyChild, qobject_cast<QObject*>(child));
|
_populate_parent(pyChild, qobject_cast<QObject*>(child));
|
||||||
|
|
@ -53,14 +53,17 @@ quiloader_load_ui(QUiLoader* self, const QString &ui_file, QWidget *parent)
|
||||||
QWidget* w = self->load(&fd, parent);
|
QWidget* w = self->load(&fd, parent);
|
||||||
fd.close();
|
fd.close();
|
||||||
if (w != 0) {
|
if (w != 0) {
|
||||||
PyObject* pyParent = Shiboken::Converter<QWidget*>::toPython(w);
|
QObject *_parent = parent;
|
||||||
|
if (!_parent)
|
||||||
|
_parent = w;
|
||||||
|
|
||||||
|
Shiboken::AutoDecRef pyParent(Shiboken::Converter<QWidget*>::toPython(_parent));
|
||||||
if (parent && parent->layout())
|
if (parent && parent->layout())
|
||||||
parent->layout()->deleteLater();
|
parent->layout()->deleteLater();
|
||||||
|
|
||||||
_populate_parent(pyParent, w);
|
_populate_parent(pyParent, _parent);
|
||||||
|
|
||||||
return pyParent;
|
return Shiboken::Converter<QWidget*>::toPython(w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Unable to open ui file");
|
PyErr_SetString(PyExc_RuntimeError, "Unable to open ui file");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue