diff options
author | Hugo Lima <hugo.lima@openbossa.org> | 2010-01-28 14:53:48 -0200 |
---|---|---|
committer | Hugo Lima <hugo.lima@openbossa.org> | 2010-01-28 17:44:39 -0200 |
commit | 1d026bf13fbb6736a1094658ba864267b0e6e8ff (patch) | |
tree | 000a772ce5e17005d47013d12e19feda4f4a3bf2 /PySide/QtGui/glue | |
parent | e902987249cfefed36addf74fda824dc445c989c (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/QtGui/glue')
-rw-r--r-- | PySide/QtGui/glue/qapplication_init.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/PySide/QtGui/glue/qapplication_init.cpp b/PySide/QtGui/glue/qapplication_init.cpp index 469e18c99..2afc6a592 100644 --- a/PySide/QtGui/glue/qapplication_init.cpp +++ b/PySide/QtGui/glue/qapplication_init.cpp @@ -1,5 +1,9 @@ // Borrowed reference to QtGui module extern PyObject* moduleQtGui; +// Global variables used to store argc and argv values, defined in QtCore binding +extern int QCoreApplicationArgCount; +extern char** QCoreApplicationArgValues; +extern void DeleteQCoreApplicationAtExit(); int SbkQApplication_Init(PyObject* self, PyObject* args, PyObject*) { @@ -14,14 +18,12 @@ int SbkQApplication_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 QApplication(argc, argv)); + SbkBaseWrapper_setCptr(self, new QApplication(QCoreApplicationArgCount, QCoreApplicationArgValues)); SbkBaseWrapper_setValidCppObject(self, 1); Shiboken::BindingManager::instance().registerWrapper(reinterpret_cast<SbkBaseWrapper*>(self)); @@ -35,5 +37,8 @@ int SbkQApplication_Init(PyObject* self, PyObject* args, PyObject*) } PyObject_SetAttrString(moduleQtGui, QAPP_MACRO, self); + Py_INCREF(self); + Py_AtExit(DeleteQCoreApplicationAtExit); + return 1; } |