Re: Signals/slots timeout
Quote:
Originally Posted by
gfunk
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.
Re: Signals/slots timeout
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)
Re: Signals/slots timeout
Something like the following?
Code:
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).