View Full Version : I need a pause (QTimer)
baray98
16th January 2008, 07:44
Hi guys i am trying to interface into a system which needs pause (wait for some time in every command). eg
signature function will do the following
send enable command
pause for some time
send signature request
pause for sometime
send signature request for another device
can i use a QTimer to create a wait inside my function? Is this possible?
baray98
Gopala Krishna
16th January 2008, 08:17
Hi guys i am trying to interface into a system which needs pause (wait for some time in every command). eg
can i use a QTimer to create a wait inside my function? Is this possible?
baray98
If the command sending function is a single function which accepts string or predefined set of parameters, then probably you can use a Queue something like this.
QQueue<QString> q;
sendSignature()
{
q.clear(); //clear pending jobs
q << "enable" << "sigrequest1" << "sigrequest2" ..;
sendCommands();
}
sendCommands()
{
if(q.isEmpty())
return;
act_sendCommand(q.head()); //this is the function responsible to send the command
q.dequeue();
QTimer::singleShot(delay, this, SLOT(sendCommands())); //call self to call subsequent commands
}
Ofcourse this system might fail if you are using multiple threads..
baray98
16th January 2008, 16:12
Good, that might work for me i dont have multiple threads i tried to make my life simple...
Any more ways gentlemen
baray98
Gopala Krishna
17th January 2008, 05:37
If you aren't using multiple thread and if you can assure no reentrancy then there is chance that this following method will also work for you
Again stressing the fact that this will fail miserably if there is chance of you calling the manualPause function while it is already in progress.
Probably you can disable the buttons/control widgets when the manualPause is in progress. (also function using manualPause won't be reentrant)
enum State
{
Paused,
Run
};
State state;
/** This function won't return till the time delay */
void manualPause()
{
state = Paused;
QTimer::singleShot(delay, this, SLOT(setRunState());
while(1) {
qApp->processEvents();
if(state == Run) break;
}
}
void setRunState()
{
state = Run;
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.