[Interest] QTest + QSignalSpy doesn't seem to work with deferred signals

Bob Hood bhood2 at comcast.net
Fri Jan 20 01:32:10 CET 2017

On 1/19/2017 2:29 AM, Viktor Engelmann wrote:
> QSignalSpy::wait has a race condition though. When the signal is emitted 
> from a different thread, it might come before you called .wait and then the 
> wait will time out and return false (so it looks like the signal wasn't 
> emitted). You can store the value of spy.size() and after the wait compare 
> it to the current spy.size(). That is more robust, but when the signal is 
> emitted before you start the .wait, the .wait will still wait for the full 
> timeout time.
> QTRY_COMPARE terminates as soon as the condition is met, so 
> QTRY_COMPARE(spy.size(), 1) is better, but it uses a timeout of only 5 
> seconds, which should be enough in most cases, but I have seen cases where a 
> signal came 11 seconds after I caused it to be emitted (due to network 
> and/or system load). I used QTRY_COMPARE_WITH_TIMEOUT instead to set a 
> higher timeout.

Thanks for the info, Viktor.  :)

More information about the Interest mailing list