aboutsummaryrefslogtreecommitdiffstats
path: root/PySide/QtCore/glue
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2010-01-28 14:53:48 -0200
committerHugo Lima <hugo.lima@openbossa.org>2010-01-28 17:44:39 -0200
commit1d026bf13fbb6736a1094658ba864267b0e6e8ff (patch)
tree000a772ce5e17005d47013d12e19feda4f4a3bf2 /PySide/QtCore/glue
parente902987249cfefed36addf74fda824dc445c989c (diff)
Ensure that QApplication instances will be alive forever until the Python VM death.
Also deletes argv when QApplication is removed. Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'PySide/QtCore/glue')
-rw-r--r--PySide/QtCore/glue/qcoreapplication_impl.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/PySide/QtCore/glue/qcoreapplication_impl.cpp b/PySide/QtCore/glue/qcoreapplication_impl.cpp
index b6d3bf731..e3210c7c4 100644
--- a/PySide/QtCore/glue/qcoreapplication_impl.cpp
+++ b/PySide/QtCore/glue/qcoreapplication_impl.cpp
@@ -1,3 +1,18 @@
+// Global variables used to store argc and argv values
+SHIBOKEN_QTCORE_API int QCoreApplicationArgCount;
+SHIBOKEN_QTCORE_API char** QCoreApplicationArgValues;
+
+/**
+ * Called at QtCore module exit
+ */
+SHIBOKEN_QTCORE_API void DeleteQCoreApplicationAtExit() {
+ if (QCoreApplication::instance()) {
+ delete QCoreApplication::instance();
+ for (int i = 0; i < QCoreApplicationArgCount; ++i)
+ delete[] QCoreApplicationArgValues[i];
+ }
+}
+
int SbkQCoreApplication_Init(PyObject* self, PyObject* args, PyObject*)
{
if (QCoreApplication::instance()) {
@@ -11,15 +26,16 @@ int SbkQCoreApplication_Init(PyObject* self, PyObject* args, PyObject*)
return -1;
}
- char** argv;
- int argc;
- if (!PySequence_to_argc_argv(PyTuple_GET_ITEM(args, 0), &argc, &argv)) {
+ if (!PySequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QCoreApplicationArgCount, &QCoreApplicationArgValues, "PySideApp")) {
PyErr_BadArgument();
return -1;
}
- SbkBaseWrapper_setCptr(self, new QCoreApplication(argc, argv));
+ SbkBaseWrapper_setCptr(self, new QCoreApplication(QCoreApplicationArgCount, QCoreApplicationArgValues));
SbkBaseWrapper_setValidCppObject(self, 1);
Shiboken::BindingManager::instance().registerWrapper(reinterpret_cast<SbkBaseWrapper*>(self));
+
+ Py_INCREF(self);
+ Py_AtExit(DeleteQCoreApplicationAtExit);
return 1;
}