diff options
-rw-r--r-- | libpyside/qproperty.cpp | 12 | ||||
-rw-r--r-- | tests/QtCore/qobject_property_test.py | 20 |
2 files changed, 21 insertions, 11 deletions
diff --git a/libpyside/qproperty.cpp b/libpyside/qproperty.cpp index b2d011e85..c4b728ac5 100644 --- a/libpyside/qproperty.cpp +++ b/libpyside/qproperty.cpp @@ -231,12 +231,14 @@ const char* qproperty_get_type(PyObject* self) PyObject* qproperty_get_object(PyObject* source, PyObject* name) { - if (PyObject_HasAttr(source, name)) { - PyObject* attr = PyObject_GenericGetAttr(source, name); - if (isQPropertyType(attr)) - return attr; + PyObject* attr = PyObject_GenericGetAttr(source, name); + if (attr && isQPropertyType(attr)) + return attr; + + if (!attr) + PyErr_Clear(); //Clear possible error caused by PyObject_GenericGetAttr + else Py_DECREF(attr); - } return 0; } diff --git a/tests/QtCore/qobject_property_test.py b/tests/QtCore/qobject_property_test.py index 7d53e0a26..1d8a16c9a 100644 --- a/tests/QtCore/qobject_property_test.py +++ b/tests/QtCore/qobject_property_test.py @@ -13,8 +13,17 @@ class MySize(QSize): '''Extended class''' pass -class ExtQObject(QObject): - registeredproperty = QProperty(int) +class ExQObject(QObject): + def __init__(self, *args, **kargs): + QObject.__init__(self, *args, **kargs) + + def setProperty(self, value): + self._value = value + + def getProperty(self): + return self._value + + registeredproperty = QProperty(int, getProperty, setProperty) class MyObject(QObject): '''Test Property''' @@ -105,7 +114,6 @@ class PropertyCase(unittest.TestCase): self.assertTrue(obj.property('foo') is mysize) - class PropertyWithConstructorCase(unittest.TestCase): '''Test case for QObject properties set using named arguments in the constructor.''' @@ -118,17 +126,17 @@ class PropertyWithConstructorCase(unittest.TestCase): self.assertRaises(AttributeError, QObject, dummy=42) def testPythonDeclaredProperty(self): - obj = ExtQObject(registeredproperty=123) + obj = ExQObject(registeredproperty=123) + self.assertEqual(obj.registeredproperty, 123) def testConstructorPropertyInQObjectDerived(self): #QTimer(property=value) for existing C++ property obj = QTimer(objectName='dummy') self.assertEqual(obj.objectName(), 'dummy') - def testPythonProperty(self): + def testReadOnlyPythonProperty(self): o = MyObject() self.assertEqual(o.pp, 42) - o.pp = 0 self.assertRaises(AttributeError, o.trySetPP) if __name__ == '__main__': |