Results 1 to 7 of 7

Thread: Delay Loop until a QPushButton pressed

  1. #1

    Default 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:

    Qt Code:
    1. for (start=0 ; start<numberOfFiles ; start++) // main Processing Loop
    2. { ...
    3. wait = true;
    4. while (wait)
    5. ; // Good For Nothing
    6. ...
    7. }
    8.  
    9. // Assume QPushButton clicked SIGNAL is properly linked to savedPressed() SLOT.
    10.  
    11. void BYDATE::savePressed () // SLOT
    12. wait=false;
    13. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2

    Default Re: Delay Loop until a QPushButton pressed

    I found one solution, which was to put :

    Qt Code:
    1. QApplication::processEvents();
    To copy to clipboard, switch view to plain text mode 

    inside the while loop.

    This solution seems to be working and is much easier than using the QEventLoop class.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Delay Loop until a QPushButton pressed


  4. #4

    Default Re: Delay Loop until a QPushButton pressed

    Quote Originally Posted by wysota View Post
    Yeah, and it's also wrong

    I didn't say it was the right solution, I only said it worked, which it does.
    I'll take a closer look at your link, when I get a chance.

    Thanks

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

  6. #6

    Default Re: Delay Loop until a QPushButton pressed

    Quote Originally Posted by wysota View Post
    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

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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).

Similar Threads

  1. Qpushbutton
    By iamhere in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2008, 04:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.