Delay Loop until a QPushButton pressed
I want to iterate through a list of files and have the program wait until a user presses the skip or save push button before going to the next file. I created a boolean variable called wait which would be set to true and changed to false when a push button is pressed. The following is a code extract showing the logic:
Code:
for (start=0 ; start<numberOfFiles ; start++) // main Processing Loop
{ ...
wait = true;
while (wait)
; // Good For Nothing
...
}
// Assume QPushButton clicked SIGNAL is properly linked to savedPressed() SLOT.
void BYDATE::savePressed () // SLOT
wait=false;
}
The above code causes the program to hang. Is it possible to change the wait variable when the program is in the while loop. I'm hoping to avoid multi-threading, if possible. I tried getchar(), but that didn't work either.
Any suggestions?
Thanks
Re: Delay Loop until a QPushButton pressed
I found one solution, which was to put :
inside the while loop.
This solution seems to be working and is much easier than using the QEventLoop class.
Re: Delay Loop until a QPushButton pressed
Re: Delay Loop until a QPushButton pressed
Quote:
Originally Posted by
wysota
Yeah, and it's also wrong ;)
I didn't say it was the right solution, I only said it worked, which it does. :rolleyes:
I'll take a closer look at your link, when I get a chance.
Thanks
Re: Delay Loop until a QPushButton pressed
It worked for now. Try running two such loops at the same time. Using QEventLoop is much better, especially that it's much easier to timeout such call and resources are used wisely.
Re: Delay Loop until a QPushButton pressed
Quote:
Originally Posted by
wysota
It worked for now. Try running two such loops at the same time. Using QEventLoop is much better, especially that it's much easier to timeout such call and resources are used wisely.
I hope you don't think I was disagreeing with you! Your points are well taken. What APPEARS to work now may cause problems down the road or in other situations, so why not do it right to begin with.
Thanks Again
Re: Delay Loop until a QPushButton pressed
I'm more against the "it's much easier than using QEventLoop" statement than about agreeing or not about some solution being proper (or not).