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>
This commit is contained in:
parent
e902987249
commit
1d026bf13f
2 changed files with 29 additions and 8 deletions
|
|
@ -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*)
|
int SbkQCoreApplication_Init(PyObject* self, PyObject* args, PyObject*)
|
||||||
{
|
{
|
||||||
if (QCoreApplication::instance()) {
|
if (QCoreApplication::instance()) {
|
||||||
|
|
@ -11,15 +26,16 @@ int SbkQCoreApplication_Init(PyObject* self, PyObject* args, PyObject*)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char** argv;
|
if (!PySequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QCoreApplicationArgCount, &QCoreApplicationArgValues, "PySideApp")) {
|
||||||
int argc;
|
|
||||||
if (!PySequence_to_argc_argv(PyTuple_GET_ITEM(args, 0), &argc, &argv)) {
|
|
||||||
PyErr_BadArgument();
|
PyErr_BadArgument();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SbkBaseWrapper_setCptr(self, new QCoreApplication(argc, argv));
|
SbkBaseWrapper_setCptr(self, new QCoreApplication(QCoreApplicationArgCount, QCoreApplicationArgValues));
|
||||||
SbkBaseWrapper_setValidCppObject(self, 1);
|
SbkBaseWrapper_setValidCppObject(self, 1);
|
||||||
Shiboken::BindingManager::instance().registerWrapper(reinterpret_cast<SbkBaseWrapper*>(self));
|
Shiboken::BindingManager::instance().registerWrapper(reinterpret_cast<SbkBaseWrapper*>(self));
|
||||||
|
|
||||||
|
Py_INCREF(self);
|
||||||
|
Py_AtExit(DeleteQCoreApplicationAtExit);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
// Borrowed reference to QtGui module
|
// Borrowed reference to QtGui module
|
||||||
extern PyObject* moduleQtGui;
|
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*)
|
int SbkQApplication_Init(PyObject* self, PyObject* args, PyObject*)
|
||||||
{
|
{
|
||||||
|
|
@ -14,14 +18,12 @@ int SbkQApplication_Init(PyObject* self, PyObject* args, PyObject*)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char** argv;
|
if (!PySequenceToArgcArgv(PyTuple_GET_ITEM(args, 0), &QCoreApplicationArgCount, &QCoreApplicationArgValues, "PySideApp")) {
|
||||||
int argc;
|
|
||||||
if (!PySequence_to_argc_argv(PyTuple_GET_ITEM(args, 0), &argc, &argv)) {
|
|
||||||
PyErr_BadArgument();
|
PyErr_BadArgument();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SbkBaseWrapper_setCptr(self, new QApplication(argc, argv));
|
SbkBaseWrapper_setCptr(self, new QApplication(QCoreApplicationArgCount, QCoreApplicationArgValues));
|
||||||
SbkBaseWrapper_setValidCppObject(self, 1);
|
SbkBaseWrapper_setValidCppObject(self, 1);
|
||||||
Shiboken::BindingManager::instance().registerWrapper(reinterpret_cast<SbkBaseWrapper*>(self));
|
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);
|
PyObject_SetAttrString(moduleQtGui, QAPP_MACRO, self);
|
||||||
|
|
||||||
|
Py_INCREF(self);
|
||||||
|
Py_AtExit(DeleteQCoreApplicationAtExit);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue