diff options
author | Renato Filho <renato.filho@openbossa.org> | 2010-08-24 17:14:40 -0300 |
---|---|---|
committer | Renato Filho <renato.filho@openbossa.org> | 2010-08-25 17:32:01 -0300 |
commit | 42d98f91c49774227b89373e44f0f6de20605c52 (patch) | |
tree | bd2b48dd7a4574c0fdcd100d59d46107d395814c /PySide/QtCore/glue | |
parent | 49ac670cfc106cccef0fac0681a92ea6db413a75 (diff) |
Fixed Qt application cleanup.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Hugo Parente Lima <hugo.pl@gmail.com>
Diffstat (limited to 'PySide/QtCore/glue')
-rw-r--r-- | PySide/QtCore/glue/qcoreapplication_init.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/PySide/QtCore/glue/qcoreapplication_init.cpp b/PySide/QtCore/glue/qcoreapplication_init.cpp index 5fcd79a3b..7601dbd1d 100644 --- a/PySide/QtCore/glue/qcoreapplication_init.cpp +++ b/PySide/QtCore/glue/qcoreapplication_init.cpp @@ -1,21 +1,30 @@ // Global variables used to store argc and argv values static int QCoreApplicationArgCount; static char** QCoreApplicationArgValues; +static bool leavingPython = false; /** * Called at QtCore module exit */ -void DeleteQCoreApplicationAtExit() { - if (QCoreApplication::instance()) { - BindingManager::instance().invalidateWrapper(QCoreApplication::instance()); - QCoreApplication::instance()->deleteLater(); - for (int i = 0; i < QCoreApplicationArgCount; ++i) - delete[] QCoreApplicationArgValues[i]; +void DeleteQCoreApplicationAtExit() +{ + leavingPython = true; + QCoreApplication *cpp = QCoreApplication::instance(); + if (cpp) { + Shiboken::BindingManager &bmngr = Shiboken::BindingManager::instance(); + PyObject* pySelf = bmngr.retrieveWrapper(cpp); + if (pySelf) + bmngr.invalidateWrapper(pySelf); + cpp->deleteLater(); } } int SbkQCoreApplication_Init(PyObject* self, PyObject* args, PyObject*) { + if (Shiboken::isUserType(self) && !Shiboken::canCallConstructor(self->ob_type, Shiboken::SbkType<QApplication >())) + return -1; + + if (QCoreApplication::instance()) { PyErr_SetString(PyExc_RuntimeError, "A QCoreApplication instance already exists."); return -1; @@ -32,14 +41,20 @@ int SbkQCoreApplication_Init(PyObject* self, PyObject* args, PyObject*) return -1; } - void* cptr = new QCoreApplication(QCoreApplicationArgCount, QCoreApplicationArgValues); + QCoreApplicationWrapper* cptr = new QCoreApplicationWrapper(QCoreApplicationArgCount, QCoreApplicationArgValues); Shiboken::setCppPointer(reinterpret_cast<SbkBaseWrapper*>(self), Shiboken::SbkType<QCoreApplication>(), cptr); + SbkBaseWrapper_setValidCppObject(self, 1); - Shiboken::BindingManager::instance().registerWrapper(reinterpret_cast<SbkBaseWrapper*>(self), cptr); + SbkBaseWrapper *sbkSelf = reinterpret_cast<SbkBaseWrapper*>(self); + sbkSelf->containsCppWrapper = 1; + sbkSelf->hasOwnership = 0; + Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr); + PySide::signalUpdateSource(self); + cptr->metaObject(); - Py_INCREF(self); Py_AtExit(DeleteQCoreApplicationAtExit); + Py_INCREF(self); return 1; } |