Connection guard, only valid signal connections will be added

This commit is contained in:
Klaus Basan
2018-07-16 15:49:59 +02:00
parent 3bfb76c1e6
commit a7947d3c87
2 changed files with 14 additions and 6 deletions

View File

@@ -17,14 +17,22 @@ namespace BlackMisc
m_connections.append(connection); m_connections.append(connection);
} }
void CConnectionGuard::append(const QMetaObject::Connection &connection) bool CConnectionGuard::append(const QMetaObject::Connection &connection)
{ {
if (!connection) { return false; }
m_connections.append(connection); m_connections.append(connection);
return true;
} }
void CConnectionGuard::append(const QList<QMetaObject::Connection> &connections) bool CConnectionGuard::append(const QList<QMetaObject::Connection> &connections)
{ {
m_connections.append(connections); int c = 0;
for (const QMetaObject::Connection &connection : connections)
{
if (!connection) { continue; }
if (this->append(connection)) { c++; }
}
return c > 0;
} }
CConnectionGuard::~CConnectionGuard() CConnectionGuard::~CConnectionGuard()

View File

@@ -50,10 +50,10 @@ namespace BlackMisc
~CConnectionGuard(); ~CConnectionGuard();
//! Add connection //! Add connection
void append(const QMetaObject::Connection &connection); bool append(const QMetaObject::Connection &connection);
//! Add connections //! Add connections
void append(const QList<QMetaObject::Connection> &connections); bool append(const QList<QMetaObject::Connection> &connections);
//! Disconnect all //! Disconnect all
int disconnectAll(); int disconnectAll();
@@ -61,6 +61,6 @@ namespace BlackMisc
private: private:
QList<QMetaObject::Connection> m_connections; QList<QMetaObject::Connection> m_connections;
}; };
} // BlackMisc } // ns
#endif #endif