Re: I need a pause (QTimer)
Quote:
Originally Posted by
baray98
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.
Code:
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..
Re: I need a pause (QTimer)
Good, that might work for me i dont have multiple threads i tried to make my life simple...
Any more ways gentlemen
baray98
Re: I need a pause (QTimer)
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)
Code:
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;
}