signals - Qt Unique connection -
i wondering either there possibility in qt, co create signal-slot connection, automatically break other connections particular slot/ signal? appreciate help.
qt doesn't provide such functionality directly. moreover, it's impossible iterate signal-slot connections, can't implement in general.
what should doing keeping track of connections initiate yourself, , removing them appropriate.
for example:
enum class connectiondisposal { dispose, keep }; class uniqueconnector { q_disable_copy(uniqueconnector) qmetaobject::connection m_conn; connectiondisposal m_cd; public: explicit uniqueconnector(connectiondisposal cd = connectiondisposal::dispose) : m_cd(cd) {} ~uniqueconnector() { if (m_cd == connectiondisposal::dispose) disconnect(); } template <typename t, typename r> qmetaobject::connection connect(const qobject * tx, t txf, const qobject * rx, r rxf, qt::connectiontype type = qt::autoconnection) { qobject::disconnect(m_conn); return m_conn = qobject::connect(tx, txf, rx, rxf, type); } template <typename t, typename r> qmetaobject::connection connect(const qobject * tx, t txf, r rxf) { qobject::disconnect(m_conn); return m_conn = qobject::connect(tx, txf, rxf); } bool disconnect() { return qobject::disconnect(m_conn); } };
the uniqueconnector
allows 1 connection exist on instance. so, each unique connection, need 1 uniqueconnector
instance. connection removed upon destruction of connector, unless specify otherwise.
Comments
Post a Comment