aboutsummaryrefslogtreecommitdiffstats
path: root/libpyside
diff options
context:
space:
mode:
Diffstat (limited to 'libpyside')
-rw-r--r--libpyside/pyside.cpp26
-rw-r--r--libpyside/pyside.h5
2 files changed, 31 insertions, 0 deletions
diff --git a/libpyside/pyside.cpp b/libpyside/pyside.cpp
index 7d9230016..c2e14350b 100644
--- a/libpyside/pyside.cpp
+++ b/libpyside/pyside.cpp
@@ -24,9 +24,11 @@
#include "pyside.h"
#include <basewrapper.h>
#include <conversions.h>
+#include <typeresolver.h>
#include <algorithm>
#include <cctype>
#include <QStack>
+#include <QCoreApplication>
#include "signalmanager.h"
#include "qproperty_p.h"
#include "qproperty.h"
@@ -98,5 +100,29 @@ void runCleanupFunctions()
}
}
+void destroyQCoreApplication()
+{
+ SignalManager::instance().clear();
+ QCoreApplication* app = QCoreApplication::instance();
+ if (!app)
+ return;
+
+ Shiboken::BindingManager& bm = Shiboken::BindingManager::instance();
+ PyObject* pyQApp = bm.retrieveWrapper(app);
+ PyTypeObject* pyQObjectType = Shiboken::TypeResolver::get("QObject*")->pythonType();
+ assert(pyQObjectType);
+
+ foreach (PyObject* pyObj, bm.getAllPyObjects()) {
+ if (pyObj != pyQApp && PyObject_TypeCheck(pyObj, pyQObjectType)) {
+ if (SbkBaseWrapper_hasOwnership(pyObj)) {
+ bm.destroyWrapper(pyObj);
+ delete static_cast<QObject*>(Shiboken::getCppPointer(pyObj, Shiboken::SbkType<QObject*>()));
+ }
+ }
+ }
+ app->flush();
+ delete app;
+}
+
} //namespace PySide
diff --git a/libpyside/pyside.h b/libpyside/pyside.h
index 2c5afb536..fe9ce3a6e 100644
--- a/libpyside/pyside.h
+++ b/libpyside/pyside.h
@@ -84,6 +84,11 @@ typedef void (*CleanupFunction)(void);
PYSIDE_API void registerCleanupFunction(CleanupFunction func);
PYSIDE_API void runCleanupFunctions();
+/**
+ * Destroy a QCoreApplication taking care of destroy all instances of QObject first.
+ */
+PYSIDE_API void destroyQCoreApplication();
+
} //namespace PySide