X-Git-Url: https://vaikene.ee/gitweb/pswgen09.html?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Fregistry.cpp;h=6c8cc620151009086eb7cb186661bb91a0170824;hb=0c61450fcffcb36a6e23ca5b083c26543d956084;hp=d93e469eaeea97185e39c9e61b7f9db0146fa261;hpb=5815060246f84e8efdf3143b4e8c7d00778168cf;p=evaf
diff --git a/src/libs/Common/registry.cpp b/src/libs/Common/registry.cpp
index d93e469..6c8cc62 100644
--- a/src/libs/Common/registry.cpp
+++ b/src/libs/Common/registry.cpp
@@ -54,13 +54,32 @@ Registry::~Registry()
bool Registry::registerInterface(QString const & name, QObject * obj)
{
- mInterfaces.insert(name, QPointer(obj));
+ // Add the interface to the list of registered interfaces and connect to
+ // the destroyed() signal.
+ mInterfaces.insert(name, obj);
+ connect(obj, SIGNAL(destroyed()), this, SLOT(interfaceDestroyed(QObject *)));
return true;
}
QObject * Registry::queryInterface(QString const & name) const
{
- QHash >::const_iterator it = mInterfaces.constFind(name);
+ Interfaces::const_iterator it = mInterfaces.constFind(name);
return it != mInterfaces.constEnd() ? *it : 0;
}
+
+void Registry::interfaceDestroyed(QObject * obj)
+{
+ // Interface object destroyed. Remove it from the list of registered
+ // interfaces.
+ Interfaces::iterator it = mInterfaces.begin();
+ Interfaces::const_iterator e = mInterfaces.end();
+ while (it != e) {
+ if (*it == obj) {
+ it = mInterfaces.erase(it);
+ }
+ else {
+ ++it;
+ }
+ }
+}