Gui: clear the list of Python wrapper when quitting the application

This commit is contained in:
wmayer
2022-10-31 11:17:41 +01:00
parent 2630df6edd
commit 58d227570d

View File

@@ -257,7 +257,10 @@ public:
QObject::connect(obj, &QObject::destroyed, this, &WrapperManager::destroyed);
}
wrappers[obj].emplace_back(pyobj);
auto& pylist = wrappers[obj];
if (std::find_if(pylist.cbegin(), pylist.cend(), [pyobj](const Py::Object& py) { return py.ptr() == pyobj; }) == pylist.end()) {
pylist.emplace_back(pyobj);
}
}
private:
@@ -283,8 +286,17 @@ private:
#endif
}
}
void clear()
{
Base::PyGILStateLocker lock;
wrappers.clear();
}
WrapperManager() = default;
WrapperManager()
{
connect(QApplication::instance(), &QCoreApplication::aboutToQuit,
this, &WrapperManager::clear);
}
~WrapperManager() = default;
};