QSignalSpy to receive signals for particular time instead of count
-
wrote on 16 Oct 2020, 17:37 last edited by
is possible to make the QSignalSpy wait for a particular time until it receives the specific signal. Right now I have this function which waits for the particular number of signal count and time. I want this function to wait for waitTimeoutMS and return if it receives a signal with specific data (instead of count). I tried bool QSignalSpy::wait(int timeout = 5000) but it return once it receives first signal.
bool waitForSpyCalled(QSignalSpy& spy, int waitTimeoutMS, int expectCount = 1) { for (int delay = waitTimeoutMS; delay > 0 && spy.count() < expectCount; delay -= 200) { QTest::qWait(200); } return spy.count() >= expectCount; }
-
Hi,
Do you mean have QSignalSpy start spying only after some delay ?
-
wrote on 16 Oct 2020, 17:53 last edited by Venkateswaran
@SGaist Actually I want to look for a particular signal for period of time. Signal will emitted continuously from application.
Like for example void signalEmitStatus(const EnumType& e);
Now the enum type will be a list of application state like
enum EnumType {
Starting,
Init,
Init config,
Checking peers,
SUCCESS
}App takes like 1000ms to reach "SUCCESS" state. So each state change gets emitted from signalEmitStatus, but some state will get skipped sometimes that's the reason I can't go with signal emit count. Either I have to collect signals for particular period of time and check the list of signals or need to spy for specific signal.
I want to catch that SUCCESS state signal
-
Then I'd rather go with the inspection of the received value. That is more solid than relying on specific timing that might change with machine power.
-
Then I'd rather go with the inspection of the received value. That is more solid than relying on specific timing that might change with machine power.
wrote on 16 Oct 2020, 18:05 last edited by@SGaist you mean to inspect each signal emit until I find SUCCESS. Is it possible to collect signals for particular period of time ?
-
I think that you are looking for qWaitFor.
1/6