aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-10-13 16:42:50 -0300
committerrenatofilho <renato.filho@openbossa.org>2010-10-13 17:01:05 -0300
commite71b215f0bb4c6b53bd74a66ab856426df51f140 (patch)
tree79ab2ad9382cf5f8d718a41641fbf8c9885a48a9
parent4c8660413a66b8e006687def786d9a82c6870094 (diff)
Fixed reference leak on uiloader.
Fixes bug #392 Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Marcelo Lira <marcelo.lira@openbossa.org>
-rw-r--r--plugins/customwidget.cpp11
-rw-r--r--tests/QtUiTools/bug_392.py12
-rw-r--r--tests/QtUiTools/pycustomwidget2.ui48
3 files changed, 66 insertions, 5 deletions
diff --git a/plugins/customwidget.cpp b/plugins/customwidget.cpp
index 78e0064d2..156b37306 100644
--- a/plugins/customwidget.cpp
+++ b/plugins/customwidget.cpp
@@ -91,7 +91,7 @@ QString PyCustomWidget::whatsThis() const
}
QWidget *PyCustomWidget::createWidget(QWidget *parent)
-{
+{
//Create a python instance and return cpp object
PyObject* pyParent;
bool unkowParent = false;
@@ -100,8 +100,11 @@ QWidget *PyCustomWidget::createWidget(QWidget *parent)
if (!pyParent) {
pyParent = Shiboken::Converter<QWidget*>::toPython(parent);
unkowParent = true;
+ } else {
+ Py_INCREF(pyParent);
}
} else {
+ Py_INCREF(Py_None);
pyParent = Py_None;
}
@@ -110,14 +113,14 @@ QWidget *PyCustomWidget::createWidget(QWidget *parent)
//Call python constructor
PyObject* result = PyObject_CallObject(m_data->pyObject, pyArgs);
-
+
QWidget* widget = 0;
if (result) {
if (unkowParent) //if parent does not exists in python, transfer the ownership to cpp
- Shiboken::BindingManager::instance().transferOwnershipToCpp(result);
+ Shiboken::BindingManager::instance().transferOwnershipToCpp(result);
else
Shiboken::setParent(pyParent, result);
-
+
widget = reinterpret_cast<QWidget*>(Shiboken::getCppPointer(result, result->ob_type));
}
diff --git a/tests/QtUiTools/bug_392.py b/tests/QtUiTools/bug_392.py
index 36b2f1091..9cc8b210b 100644
--- a/tests/QtUiTools/bug_392.py
+++ b/tests/QtUiTools/bug_392.py
@@ -2,7 +2,7 @@ import unittest
import os
from helper import UsesQApplication
-from PySide import QtCore, QtGui, QtDeclarative
+from PySide import QtGui, QtDeclarative
from PySide.QtUiTools import QUiLoader
class MyWidget(QtGui.QComboBox):
@@ -40,6 +40,16 @@ class BugTest(UsesQApplication):
self.assert_(isinstance(result.custom, MyWidget))
self.assert_(result.custom.isPython())
+ def testPythonCustomWidgetsTwice(self):
+ w = QtGui.QWidget()
+ loader = QUiLoader()
+ loader.registerCustomWidget(MyWidget)
+
+ filePath = os.path.join(os.path.dirname(__file__), 'pycustomwidget2.ui')
+ result = loader.load(filePath, w)
+ self.assert_(isinstance(result.custom, MyWidget))
+ self.assert_(isinstance(result.custom2, MyWidget))
+ self.assert_(result.custom.isPython())
if __name__ == '__main__':
unittest.main()
diff --git a/tests/QtUiTools/pycustomwidget2.ui b/tests/QtUiTools/pycustomwidget2.ui
new file mode 100644
index 000000000..8826ac1fb
--- /dev/null
+++ b/tests/QtUiTools/pycustomwidget2.ui
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>qwidget</class>
+ <widget class="QWidget" name="qwidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string/>
+ </property>
+
+ <widget class="MyWidget" name="custom">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>10</y>
+ <width>79</width>
+ <height>23</height>
+ </rect>
+ </property>
+ </widget>
+
+ <widget class="MyWidget" name="custom2">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>10</y>
+ <width>79</width>
+ <height>23</height>
+ </rect>
+ </property>
+ </widget>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>MyWidget</class>
+ <extends>QComboBox</extends>
+ <header>customwidget</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>