GUIInvoke takes a QObject* to avoid callbacks after object lifetime

* The GUIInvoke object takes a QObject, and uses QPointer to check that
  it hasn't been deleted when the callback fires. This prevents delayed
  callbacks from executing after the object has been deleted and
  crashing.
* In most cases the pointer is just 'this'.
This commit is contained in:
baldurk
2018-05-08 11:54:34 +01:00
parent c880def5ef
commit 082ab4d75d
25 changed files with 113 additions and 108 deletions
+4 -4
View File
@@ -233,7 +233,7 @@ void RemoteManager::refreshHost(RDTreeWidgetItem *node)
host->CheckStatus();
GUIInvoke::call(
[this, node, host]() { setRemoteServerLive(node, host->serverRunning, host->busy); });
this, [this, node, host]() { setRemoteServerLive(node, host->serverRunning, host->busy); });
uint32_t nextIdent = 0;
@@ -265,7 +265,7 @@ void RemoteManager::refreshHost(RDTreeWidgetItem *node)
RemoteConnect tag(host->hostname, host->Name(), nextIdent);
GUIInvoke::call([this, node, target, running, tag]() {
GUIInvoke::call(this, [this, node, target, running, tag]() {
RDTreeWidgetItem *child = new RDTreeWidgetItem({target, running});
setRemoteConnect(child, tag);
node->addChild(child);
@@ -276,11 +276,11 @@ void RemoteManager::refreshHost(RDTreeWidgetItem *node)
}
}
GUIInvoke::call([node]() { node->setItalic(false); });
GUIInvoke::call(this, [node]() { node->setItalic(false); });
m_Lookups.acquire();
GUIInvoke::call([this]() { updateStatus(); });
GUIInvoke::call(this, [this]() { updateStatus(); });
});
th->selfDelete(true);
th->start();