Guard QTimer::singleShot

This commit is contained in:
Klaus Basan
2018-05-06 20:24:40 +02:00
committed by Roland Winklmeier
parent 3ecb7b1f94
commit 3f4cb7529c
4 changed files with 33 additions and 8 deletions

View File

@@ -38,6 +38,7 @@
#include <QThread> #include <QThread>
#include <Qt> #include <Qt>
#include <QtGlobal> #include <QtGlobal>
#include <QPointer>
using namespace BlackConfig; using namespace BlackConfig;
using namespace BlackMisc; using namespace BlackMisc;
@@ -68,12 +69,18 @@ namespace BlackCore
this->restoreSimulatorPlugins(); this->restoreSimulatorPlugins();
connect(&m_weatherManager, &CWeatherManager::weatherGridReceived, this, &CContextSimulator::weatherGridReceived); connect(&m_weatherManager, &CWeatherManager::weatherGridReceived, this, &CContextSimulator::weatherGridReceived);
// seems to be redundant, as changed sim will cause changed cache
// connect(&m_modelSetLoader, &CAircraftModelSetLoader::simulatorChanged, this, &CDigestSignal::modelSetChanged);
connect(&m_modelSetLoader, &CAircraftModelSetLoader::cacheChanged, this, &CContextSimulator::modelSetChanged); connect(&m_modelSetLoader, &CAircraftModelSetLoader::cacheChanged, this, &CContextSimulator::modelSetChanged);
// seems to be redundant, as changed simulator will cause changed cache
// connect(&m_modelSetLoader, &CAircraftModelSetLoader::simulatorChanged, this, &CDigestSignal::modelSetChanged);
// deferred init of last model set, if no other data are set in meantime // deferred init of last model set, if no other data are set in meantime
QTimer::singleShot(1250, this, &CContextSimulator::initByLastUsedModelSet); const QPointer<CContextSimulator> myself(this);
QTimer::singleShot(1250, this, [ = ]
{
if (!myself) { return; }
this->initByLastUsedModelSet();
});
} }
CContextSimulator *CContextSimulator::registerWithDBus(CDBusServer *server) CContextSimulator *CContextSimulator::registerWithDBus(CDBusServer *server)

View File

@@ -32,7 +32,13 @@ namespace BlackGui
this->setPlaceholderText(".dot commands"); this->setPlaceholderText(".dot commands");
} }
QTimer::singleShot(5000, &m_dsCommandTooltip, &CDigestSignal::inputSignal); const QPointer<CCommandInput> myself(this);
QTimer::singleShot(5000, this, [ = ]
{
if (!myself) { return; }
m_dsCommandTooltip.inputSignal();
});
if (sGui && sGui->supportsContexts()) if (sGui && sGui->supportsContexts())
{ {
if (sGui->getIContextSimulator()) if (sGui->getIContextSimulator())

View File

@@ -35,6 +35,7 @@
#include <QToolButton> #include <QToolButton>
#include <Qt> #include <Qt>
#include <QtGlobal> #include <QtGlobal>
#include <QPointer>
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Network; using namespace BlackMisc::Network;
@@ -453,7 +454,13 @@ namespace BlackGui
{ {
std::function<void()> f = m_pendingMessageCalls.front(); std::function<void()> f = m_pendingMessageCalls.front();
m_pendingMessageCalls.removeFirst(); m_pendingMessageCalls.removeFirst();
QTimer::singleShot(500, this, f); const QPointer<COverlayMessages> myself(this);
QTimer::singleShot(500, this, [ = ]
{
if (!myself) { return; }
if (!sGui || sGui->isShuttingDown()) { return; }
f();
});
} }
} }

View File

@@ -9,6 +9,7 @@
#include "digestsignal.h" #include "digestsignal.h"
#include "threadutils.h" #include "threadutils.h"
#include <QPointer>
namespace BlackMisc namespace BlackMisc
{ {
@@ -17,7 +18,12 @@ namespace BlackMisc
if (!CThreadUtils::isCurrentThreadObjectThread(this)) if (!CThreadUtils::isCurrentThreadObjectThread(this))
{ {
// call in correct thread // call in correct thread
QTimer::singleShot(0, this, &CDigestSignal::inputSignal); const QPointer<CDigestSignal> myself(this);
QTimer::singleShot(0, this, [ = ]
{
if (!myself) { return; }
this->inputSignal();
});
return; return;
} }
@@ -33,7 +39,7 @@ namespace BlackMisc
{ {
m_timer.stop(); m_timer.stop();
m_inputsCount = 0; m_inputsCount = 0;
emit digestSignal(); emit this->digestSignal();
} }
void CDigestSignal::init(int maxDelayMs) void CDigestSignal::init(int maxDelayMs)
@@ -42,5 +48,4 @@ namespace BlackMisc
m_timer.setSingleShot(true); m_timer.setSingleShot(true);
m_timer.setInterval(maxDelayMs); m_timer.setInterval(maxDelayMs);
} }
} // namespace } // namespace