PDA

View Full Version : Signals/slots timeout



gfunk
17th August 2007, 00:13
When you connect a oneshot signal to a slot, you may often want the connection to have a timeout that calls a different slot/function if the original signal never arrives. Does anyone know of a good clean way to write this without having to create another QTimer instance and another connection to manage?

magland
17th August 2007, 00:41
When you connect a oneshot signal to a slot, you may often want the connection to have a timeout that calls a different slot/function if the original signal never arrives. Does anyone know of a good clean way to write this without having to create another QTimer instance and another connection to manage?

Why would the timer signal "never arrive"? My understanding is that it will always arrive... it just may be late if processing loop is busy. If late is a problem, you could use QTime.start(), QTime.ellapsed() to check. If you are worried that the single-shot timer signal may somehow be discarded, you could go for a multi-shot timer, and just stop it after the first successful timeout.

gfunk
17th August 2007, 01:10
Yes... I could do that. I guess what i'm looking for is a way to abstract out the details of using a QTime. something simple like connect(this, signal, this, slot-function, slot-function-if-timed-out, timeout value)

wysota
17th August 2007, 02:19
Something like the following?


QTimer::singleShot(timeout_value, this, SLOT(on_timeout()))

In case you're worrying that a timer may be late I can say that on most common systems you can do nothing about it as the systems are rarely real-time systems that guarantee response times (neither Windows nor MacOS is a real-time system).