diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-11-09 03:03:05 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-11-09 03:03:05 +0100 |
commit | 41117374263eb96d2515a5868a955949e7b7ff27 (patch) | |
tree | 902087a06acda58101d8053872d3ccb133fb3e48 /src/core | |
parent | 25b1c54aac84564a3e5f47c1afc1aab25baebf45 (diff) | |
parent | beba8d925721c12fe8a8c924f0594adb0ced387e (diff) |
Merge remote-tracking branch 'origin/5.14' into 5.15
Change-Id: I33c8bbabb3f164b3e3d56ca8902222ed6d3a9647
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/nodes/qnode.cpp | 5 | ||||
-rw-r--r-- | src/core/nodes/qnode_p.h | 21 |
2 files changed, 17 insertions, 9 deletions
diff --git a/src/core/nodes/qnode.cpp b/src/core/nodes/qnode.cpp index 739b46cfe..af16eaa21 100644 --- a/src/core/nodes/qnode.cpp +++ b/src/core/nodes/qnode.cpp @@ -792,10 +792,9 @@ QNode::~QNode() { Q_D(QNode); // Disconnect each connection that was stored - for (auto it = d->m_destructionConnections.begin(), end = d->m_destructionConnections.end(); it != end; ++it) - QObject::disconnect(it.value()); + for (const auto &nodeConnectionPair : qAsConst(d->m_destructionConnections)) + QObject::disconnect(nodeConnectionPair.second); d->m_destructionConnections.clear(); - Q_EMIT nodeDestroyed(); // Notify the backend that the parent lost this node as a child and diff --git a/src/core/nodes/qnode_p.h b/src/core/nodes/qnode_p.h index a7a300a5e..61aa81c81 100644 --- a/src/core/nodes/qnode_p.h +++ b/src/core/nodes/qnode_p.h @@ -124,7 +124,7 @@ public: // If the node is destoyed, we make sure not to keep a dangling pointer to it Q_Q(QNode); auto f = [q, func]() { (static_cast<Caller *>(q)->*func)(nullptr); }; - m_destructionConnections.insert(node, QObject::connect(node, &QNode::nodeDestroyed, f)); + m_destructionConnections.push_back({node, QObject::connect(node, &QNode::nodeDestroyed, f)}); } template<typename Caller, typename NodeType> @@ -133,7 +133,7 @@ public: // If the node is destoyed, we make sure not to keep a dangling pointer to it Q_Q(QNode); auto f = [q, func, node]() { (static_cast<Caller *>(q)->*func)(node); }; - m_destructionConnections.insert(node, QObject::connect(node, &QNode::nodeDestroyed, f)); + m_destructionConnections.push_back({node, QObject::connect(node, &QNode::nodeDestroyed, f)}); } template<typename Caller, typename ValueType> @@ -146,7 +146,7 @@ public: // If the node is destoyed, we make sure not to keep a dangling pointer to it Q_Q(QNode); auto f = [q, func, resetValue]() { (static_cast<Caller *>(q)->*func)(resetValue); }; - m_destructionConnections.insert(node, QObject::connect(node, &QNode::nodeDestroyed, f)); + m_destructionConnections.push_back({node, QObject::connect(node, &QNode::nodeDestroyed, f)}); } template<typename Caller, typename NodeType> @@ -154,12 +154,21 @@ public: { // If the node is destoyed, we make sure not to keep a dangling pointer to it auto f = [this, func, node]() { (static_cast<Caller *>(this)->*func)(node); }; - m_destructionConnections.insert(node, QObject::connect(node, &QNode::nodeDestroyed, f)); + m_destructionConnections.push_back({node, QObject::connect(node, &QNode::nodeDestroyed, f)}); } void unregisterDestructionHelper(QNode *node) { - QObject::disconnect(m_destructionConnections.take(node)); + m_destructionConnections.erase(std::remove_if(m_destructionConnections.begin(), + m_destructionConnections.end(), + [node] (const QPair<QNode *, QMetaObject::Connection> &nodeConnectionPair) { + if (nodeConnectionPair.first == node) { + QObject::disconnect(nodeConnectionPair.second); + return true; + } + return false; + }), + m_destructionConnections.end()); } static const QMetaObject *findStaticMetaObject(const QMetaObject *metaObject); @@ -184,7 +193,7 @@ private: friend class PropertyChangeHandler<QNodePrivate>; bool m_propertyChangesSetup; PropertyChangeHandler<QNodePrivate> m_signals; - QHash<QNode *, QMetaObject::Connection> m_destructionConnections; + QVector<QPair<QNode *, QMetaObject::Connection>> m_destructionConnections; }; class NodePostConstructorInit : public QObject |