aboutsummaryrefslogtreecommitdiffstats
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>2012-03-08 16:56:16 -0300
commitdde75099f284a1c44773501fde77dc17d445028d (patch)
tree781fb8969f7d4412448d7ac6cb72d9e7616f892e
parent64ffc4f61b874e461c559495ece6f963ce5153ee (diff)
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 1fc802012..7dfd7a622 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 be3fb3cbb..2c842d3d1 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 000000000..3cc343f58
--- /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 000000000..a9c0aea43
--- /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
+ {
+
+ }
+}