Separates QObjects with python ownership before start destructing then.

This avoid list changes during the destruction.

Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
          Marcelo Lira <marcelo.lira@openbossa.org>
This commit is contained in:
Renato Araujo Oliveira Filho 2010-11-21 19:01:57 -03:00
commit 934f291fd9

View file

@ -114,12 +114,21 @@ void destroyQCoreApplication()
PyTypeObject* pyQObjectType = Shiboken::TypeResolver::get("QObject*")->pythonType(); PyTypeObject* pyQObjectType = Shiboken::TypeResolver::get("QObject*")->pythonType();
assert(pyQObjectType); assert(pyQObjectType);
QList<SbkObject*> objects;
//filter only QObjects which we have ownership, this will avoid list changes during the destruction of some parent object
foreach (SbkObject* pyObj, bm.getAllPyObjects()) { foreach (SbkObject* pyObj, bm.getAllPyObjects()) {
if (pyObj != pyQApp && PyObject_TypeCheck(pyObj, pyQObjectType)) { if (pyObj != pyQApp && PyObject_TypeCheck(pyObj, pyQObjectType)) {
if (Shiboken::Wrapper::hasOwnership(pyObj)) if (Shiboken::Wrapper::hasOwnership(pyObj))
objects << pyObj;
}
}
//Now we can destroy all object in the list
foreach (SbkObject* pyObj, objects)
Shiboken::callCppDestructor<QObject>(Shiboken::Wrapper::cppPointer(pyObj, Shiboken::SbkType<QObject*>())); Shiboken::callCppDestructor<QObject>(Shiboken::Wrapper::cppPointer(pyObj, Shiboken::SbkType<QObject*>()));
}
} // in the end destroy app
delete app; delete app;
} }