Use QTimer::singleShot() to delay signal from MessageReply
This commit is contained in:
@@ -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();
|
||||||
|
|
||||||
|
|||||||
@@ -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_);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user