mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
Ref T730, use an event loop with parent "this"
* central function to get QEventLoop (this can also be used to set a timeout) * do NOT use sApp as parent -> parent must be in same thread
This commit is contained in:
committed by
Mat Sutcliffe
parent
e4e4dd090e
commit
b802933422
@@ -61,7 +61,7 @@ namespace BlackCore
|
||||
{"networkversion", networkVersion.toString()},
|
||||
};
|
||||
|
||||
QPointer<QEventLoop> loop(new QEventLoop(sApp));
|
||||
QPointer<QEventLoop> loop(this->newEventLoop());
|
||||
QNetworkRequest request(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
@@ -161,7 +161,7 @@ namespace BlackCore
|
||||
{
|
||||
if (isShuttingDown()) { return {}; }
|
||||
|
||||
QPointer<QEventLoop> loop(new QEventLoop(sApp));
|
||||
QPointer<QEventLoop> loop(this->newEventLoop());
|
||||
QByteArray receivedData;
|
||||
|
||||
// posted in QAM thread, reply is nullptr if called from another thread
|
||||
@@ -197,7 +197,7 @@ namespace BlackCore
|
||||
{
|
||||
if (isShuttingDown()) { return {}; }
|
||||
|
||||
QPointer<QEventLoop> loop(new QEventLoop(sApp));
|
||||
QPointer<QEventLoop> loop(this->newEventLoop());
|
||||
QByteArray receivedData;
|
||||
|
||||
// posted in QAM thread, reply is nullptr if called from another thread
|
||||
@@ -295,7 +295,7 @@ namespace BlackCore
|
||||
{
|
||||
if (QDateTime::currentDateTimeUtc() > m_expiryLocalUtc.addSecs(-5 * 60))
|
||||
{
|
||||
connectTo(m_username, m_password, m_networkVersion);
|
||||
this->connectTo(m_username, m_password, m_networkVersion);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,6 +327,16 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
QEventLoop *CApiServerConnection::newEventLoop()
|
||||
{
|
||||
QEventLoop *loop = new QEventLoop(this);
|
||||
if (sApp)
|
||||
{
|
||||
QObject::connect(sApp, &CApplication::aboutToShutdown, loop, &QEventLoop::quit, Qt::QueuedConnection);
|
||||
}
|
||||
return loop;
|
||||
}
|
||||
|
||||
bool CApiServerConnection::isShuttingDown()
|
||||
{
|
||||
return !sApp || sApp->isShuttingDown();
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace BlackCore
|
||||
{
|
||||
if (! m_isAuthenticated)
|
||||
{
|
||||
BlackMisc::CLogMessage(this).debug(u"AFV not authenticated");
|
||||
CLogMessage(this).debug(u"AFV not authenticated");
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -149,6 +149,9 @@ namespace BlackCore
|
||||
//! Message if reply has error
|
||||
void logRequestDuration(const QNetworkReply *reply, const QString &addMsg = {});
|
||||
|
||||
//! Get QLoop for network access, using class must delete the loop
|
||||
QEventLoop *newEventLoop();
|
||||
|
||||
//! Application shutting down
|
||||
static bool isShuttingDown();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user