Use QTimer::singleShot() to delay signal from MessageReply

This commit is contained in:
Jonas Kvinge
2021-02-16 18:50:43 +01:00
parent f908336ec6
commit b1e1c704b1
2 changed files with 5 additions and 7 deletions

View File

@@ -40,7 +40,7 @@ void _MessageReplyBase::Abort() {
finished_ = true; finished_ = true;
success_ = false; success_ = false;
emit Finished(success_); emit Finished();
qLog(Debug) << "Releasing ID" << id() << "(aborted)"; qLog(Debug) << "Releasing ID" << id() << "(aborted)";
semaphore_.release(); semaphore_.release();

View File

@@ -20,9 +20,9 @@
#include <QtGlobal> #include <QtGlobal>
#include <QObject> #include <QObject>
#include <QThread>
#include <QSemaphore> #include <QSemaphore>
#include <QString> #include <QString>
#include <QTimer>
#include "core/logging.h" #include "core/logging.h"
@@ -45,7 +45,7 @@ class _MessageReplyBase : public QObject {
void Abort(); void Abort();
signals: signals:
void Finished(bool success); void Finished();
protected: protected:
bool finished_; bool finished_;
@@ -89,10 +89,8 @@ void MessageReply<MessageType>::SetReply(const MessageType &message) {
qLog(Debug) << "Releasing ID" << id() << "(finished)"; qLog(Debug) << "Releasing ID" << id() << "(finished)";
semaphore_.release(); semaphore_.release();
// The signal is not always emitted without this. // Delay the signal as workaround to fix the signal periodically not emitted.
QThread::usleep(10); QTimer::singleShot(1, this, &_MessageReplyBase::Finished);
emit Finished(success_);
} }