summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-11-01 17:29:01 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2011-11-01 18:10:41 -0200
commit8e5f57067e076eec733ee9540602db10714496aa (patch)
tree1c0e825916823f655ba315d7f2595e75b44378b3
parent2a19232a751b73105388fd52d78363d69bb54d7a (diff)
downloadpyside-8e5f57067e076eec733ee9540602db10714496aa.tar.gz
pyside-8e5f57067e076eec733ee9540602db10714496aa.tar.xz
pyside-8e5f57067e076eec733ee9540602db10714496aa.zip
Fix bug 1029 - "qmlRegisterType Fails to Increase the Ref Count"
-rw-r--r--PySide/QtDeclarative/pysideqmlregistertype.cpp3
-rw-r--r--tests/QtDeclarative/CMakeLists.txt1
-rw-r--r--tests/QtDeclarative/bug_1029.py29
-rw-r--r--tests/QtDeclarative/bug_1029.qml15
4 files changed, 48 insertions, 0 deletions
diff --git a/PySide/QtDeclarative/pysideqmlregistertype.cpp b/PySide/QtDeclarative/pysideqmlregistertype.cpp
index 1fc8020..7dfd7a6 100644
--- a/PySide/QtDeclarative/pysideqmlregistertype.cpp
+++ b/PySide/QtDeclarative/pysideqmlregistertype.cpp
@@ -113,6 +113,9 @@ int PySide::qmlRegisterType(PyObject* pyObj, const char* uri, int versionMajor,
QMetaObject* metaObject = reinterpret_cast<QMetaObject*>(ObjectType::getTypeUserData(reinterpret_cast<SbkObjectType*>(pyObj)));
Q_ASSERT(metaObject);
+ // Inc ref the type object, don't worry about dec ref them because there's no way to unregister a QML type
+ Py_INCREF(pyObj);
+
// All ready... now the ugly code begins... :-)
pyTypes[nextType] = pyObj;
diff --git a/tests/QtDeclarative/CMakeLists.txt b/tests/QtDeclarative/CMakeLists.txt
index be3fb3c..2c842d3 100644
--- a/tests/QtDeclarative/CMakeLists.txt
+++ b/tests/QtDeclarative/CMakeLists.txt
@@ -10,6 +10,7 @@ PYSIDE_TEST(bug_926.py)
PYSIDE_TEST(bug_951.py)
PYSIDE_TEST(bug_995.py)
PYSIDE_TEST(bug_997.py)
+PYSIDE_TEST(bug_1029.py)
PYSIDE_TEST(qdeclarativenetwork_test.py)
PYSIDE_TEST(qdeclarativeview_test.py)
PYSIDE_TEST(connect_python_qml.py)
diff --git a/tests/QtDeclarative/bug_1029.py b/tests/QtDeclarative/bug_1029.py
new file mode 100644
index 0000000..3cc343f
--- /dev/null
+++ b/tests/QtDeclarative/bug_1029.py
@@ -0,0 +1,29 @@
+from PySide.QtCore import *
+from PySide.QtGui import *
+from PySide.QtDeclarative import *
+
+import sys
+import gc
+
+def register_qml_types():
+ class TestClass(QDeclarativeItem):
+ def __init__(self, parent = None):
+ QDeclarativeItem.__init__(self, parent)
+
+ qmlRegisterType(TestClass, "UserTypes", 1, 0, "TestClass")
+
+def main():
+ app = QApplication([])
+
+ # reg qml types here
+ register_qml_types()
+
+ # force gc to run
+ gc.collect()
+
+ view = QDeclarativeView()
+ url = QUrl(__file__.replace(".py", ".qml"))
+ view.setSource(url)
+
+if __name__ == "__main__":
+ main()
diff --git a/tests/QtDeclarative/bug_1029.qml b/tests/QtDeclarative/bug_1029.qml
new file mode 100644
index 0000000..a9c0aea
--- /dev/null
+++ b/tests/QtDeclarative/bug_1029.qml
@@ -0,0 +1,15 @@
+import QtQuick 1.0
+import UserTypes 1.0
+
+Rectangle
+{
+ width: 200
+ height: 200
+
+ color: "#ff0000"
+
+ TestClass
+ {
+
+ }
+}