X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=blobdiff_plain;f=src%2Flibs%2FCommon%2Fregistry.cpp;h=37b47e03e4037208427242734e755b9650bdae9a;hb=13dedf19c628b9967e4c4106ab0fd967f1df0b90;hp=c0f9cae9e1f4e4330213f20d3d6a758fc044e447;hpb=688e916955a6b848dbbae1f65ae85a73593ed680;p=evaf
diff --git a/src/libs/Common/registry.cpp b/src/libs/Common/registry.cpp
index c0f9cae..37b47e0 100644
--- a/src/libs/Common/registry.cpp
+++ b/src/libs/Common/registry.cpp
@@ -41,7 +41,7 @@ using namespace eVaf::Common::Internal;
Registry::Registry()
: iRegistry()
{
- setObjectName(QString("%1-iRegistry").arg(VER_MODULENAME_STR));
+ setObjectName(QString("%1-iRegistry").arg(VER_MODULE_NAME_STR));
// Register our own interface
registerInterface("iRegistry", this);
@@ -54,11 +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(QObject *)), this, SLOT(interfaceDestroyed(QObject *)));
+
+ return true;
}
-QObject * Registry::queryInterface(QString const & name)
+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;
+ }
+ }
+}