X-Git-Url: https://vaikene.ee/gitweb/gitweb.cgi?p=evaf;a=blobdiff_plain;f=src%2Flibs%2FCommon%2Fregistry.cpp;fp=src%2Flibs%2FCommon%2Fregistry.cpp;h=6c8cc620151009086eb7cb186661bb91a0170824;hp=661d2c7d6717d2ad9bd1f43768a3679fb38b96d3;hb=a81a943bee20df3c7eb34bafb3e3fe878facfe4e;hpb=51afea61c3cf72248b2998f6874a354b49ed12ca diff --git a/src/libs/Common/registry.cpp b/src/libs/Common/registry.cpp index 661d2c7..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, QWeakPointer(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); - return it != mInterfaces.constEnd() ? (*it).data() : 0; + 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; + } + } }