summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Samir <[email protected]>2024-09-04 17:21:39 +0300
committerAhmad Samir <[email protected]>2024-10-03 23:03:26 +0300
commit401a840adbe11e70694578f4b3e283b9cf91ce72 (patch)
tree333e7464f4ff72693509798198aec39ae8f3c7d2
parentf4076f1058b97f92f65d668a274aa3bbd6d302f7 (diff)
examples/network/network-chat: use QBasicTimer instead of raw timer IDs
Change-Id: I6ea464a6d19c775edca187fea1d7cd82f5f22d3f Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r--examples/network/network-chat/connection.cpp16
-rw-r--r--examples/network/network-chat/connection.h3
2 files changed, 9 insertions, 10 deletions
diff --git a/examples/network/network-chat/connection.cpp b/examples/network/network-chat/connection.cpp
index 0f59cc91ede..fa4cb812f9e 100644
--- a/examples/network/network-chat/connection.cpp
+++ b/examples/network/network-chat/connection.cpp
@@ -6,6 +6,8 @@
#include <QTimerEvent>
+using namespace std::chrono_literals;
+
static const int TransferTimeout = 30 * 1000;
static const int PongTimeout = 60 * 1000;
static const int PingInterval = 5 * 1000;
@@ -85,10 +87,9 @@ bool Connection::sendMessage(const QString &message)
void Connection::timerEvent(QTimerEvent *timerEvent)
{
- if (timerEvent->timerId() == transferTimerId) {
+ if (timerEvent->matches(transferTimer)) {
abort();
- killTimer(transferTimerId);
- transferTimerId = -1;
+ transferTimer.stop();
}
}
@@ -159,10 +160,7 @@ void Connection::processReadyRead()
// Next state: no command read
reader.leaveContainer();
- if (transferTimerId != -1) {
- killTimer(transferTimerId);
- transferTimerId = -1;
- }
+ transferTimer.stop();
processData();
}
@@ -171,8 +169,8 @@ void Connection::processReadyRead()
if (reader.lastError() != QCborError::EndOfFile)
abort(); // parse error
- if (transferTimerId != -1 && reader.containerDepth() > 1)
- transferTimerId = startTimer(TransferTimeout);
+ if (transferTimer.isActive() && reader.containerDepth() > 1)
+ transferTimer.start(TransferTimeout * 1ms, this);
}
void Connection::sendPing()
diff --git a/examples/network/network-chat/connection.h b/examples/network/network-chat/connection.h
index 4b063e7def8..d5beaf1c722 100644
--- a/examples/network/network-chat/connection.h
+++ b/examples/network/network-chat/connection.h
@@ -4,6 +4,7 @@
#ifndef CONNECTION_H
#define CONNECTION_H
+#include <QBasicTimer>
#include <QCborStreamReader>
#include <QCborStreamWriter>
#include <QElapsedTimer>
@@ -69,7 +70,7 @@ private:
QByteArray peerUniqueId;
ConnectionState state = WaitingForGreeting;
DataType currentDataType = Undefined;
- int transferTimerId = -1;
+ QBasicTimer transferTimer;
bool isGreetingMessageSent = false;
};