Results 1 to 4 of 4

Thread: how to make program wait

  1. #1
    Join Date
    May 2006
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question how to make program wait

    Hello everyone,

    I want to make presentation of sorting algorithms in QT. I've written algorithms for example (only overview):

    Qt Code:
    1. for( int r=count-1; r>0; --r ){
    2. for( int i=0; i<r; ++i ){
    3. if( elements[i]>elements[i+1] ) exch(elements[i], elements[i+1]);
    4. update();
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 
    In paintEvent function there are rectangles changing it's places after every move - redrawing after every `update()`
    But, unfortunately it is going so fast that I can only see the final effect of sorting.

    All I want is to WAIT for a second before every `update`. It really doesn't matter if it should be pure C++ or QT code.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to make program wait

    You can't wait in a Qt program, because Qt is event-driven. Event loop must be running, so that GUI can be redrawn.

    In your situation the easiest solution is IMO to implement a single iteration of sorting algorithm in a slot and connect that slot to the QTimer::timeout() signal. This way you can control the time between iterations and even implement single-stepping.

  3. #3
    Join Date
    Jan 2006
    Location
    South Carolina, USA
    Posts
    34
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to make program wait

    Well you could make the function in your class that calls the update() a slot and instead of calling it manually use a QTimer.. See here:
    http://doc.trolltech.com/4.1/qtimer.html

    EDIT:
    Don't you hate it when you post just about the same response as someone else at the same time.. O-Well...

  4. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to make program wait

    Quote Originally Posted by michael
    Don't you hate it when you post just about the same response as someone else at the same time.. O-Well...
    I posted about this here

Similar Threads

  1. Qt/Embedded Installation error during make
    By mahe2310 in forum Installation and Deployment
    Replies: 5
    Last Post: 7th September 2006, 04:05
  2. Release my simple program to other users ?
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 9th July 2006, 23:42
  3. why does qt program meet segmentation fault?
    By wquanw in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 15th May 2006, 16:52
  4. Enter key causing program to exit
    By welby in forum Qt Programming
    Replies: 2
    Last Post: 9th March 2006, 16:11
  5. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2006, 23:11

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.