Event processing and orders
-
Hello,
I want to have a connection timeout for QTcpSocket and have a few questions (also see pseudocode below):
Will
QObject::killTimer()
drop any pending events of the passed timer?
Meaning, is it guaranteed that notimerEvent()
will occur afterkillTimer()
was called?And is it possible that the
QTcpSocket::connected()
signal event is queued but before it is processed, other events (like timer events) can occur?Could the following happen?:
The connection attempt succeeds, Qt internally queues theQTcpSocket::connected()
signal event but by chance, thetimerEvent()
is called beforeSltConnected()
.
So,OnConnected(false)
is called but then, the qeueued connected-event is processed andOnConnected(true);
is called, so I have twoOnConnected()
calls which I would like to avoid.Of course I could use a
Qt::DirectConnection
, but then again my question is ifkillTimer()
insideClient::SltConnected()
guarantees thatClient::timerEvent()
will not be called anymore (if it was possibly already queued).// Pseudocode connect(&socket, &QTcpSocket::connected, this, &Client::SltConnected, Qt::QueuedConnection); Client::Connect() { startTimer(1000); socket.connectToHost(); } Client::SltConnected() { killTimer(); OnConnected(true); } Client::timerEvent() { killTimer(); socket.abort(); OnConnected(false); }
Thank you very much!