From dde75099f284a1c44773501fde77dc17d445028d Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Tue, 1 Nov 2011 17:29:01 -0200 Subject: Fix bug 1029 - "qmlRegisterType Fails to Increase the Ref Count" --- PySide/QtDeclarative/pysideqmlregistertype.cpp | 3 +++ tests/QtDeclarative/CMakeLists.txt | 1 + tests/QtDeclarative/bug_1029.py | 29 ++++++++++++++++++++++++++ tests/QtDeclarative/bug_1029.qml | 15 +++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 tests/QtDeclarative/bug_1029.py create mode 100644 tests/QtDeclarative/bug_1029.qml 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(ObjectType::getTypeUserData(reinterpret_cast(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 + { + + } +} -- cgit v1.2.3