Results 1 to 4 of 4

Thread: problem with msleep

  1. #1
    Join Date
    Dec 2007
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default problem with msleep

    Hi,
    I'm having a problem with msleep function void QThread::msleep ( unsigned long msecs )
    I dont really know how to use it.
    I have a class "Labirynt" and a function in it: void Generate();
    Something like this:
    Qt Code:
    1. void Labirynt::Generate()
    2. {
    3. for(int i=10; i<100; i++)
    4. {
    5. //mathematical calculations (these are changing variables which are used in
    6. // Labirynt::paintEvent [this is why i use update();])
    7. QThread::msleep(20);
    8. update();
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    My Error:
    c:/Qt/4.3.3/include/QtCore/../../src/corelib/thread/qthread.h:108: error: `static void QThread::msleep(long unsigned int)' is protected
    labirynt.cpp:67: error: within this context

    What should i do to make it work?
    When i use sleep from standard library program hangs up.
    When i use my own sleep function program hangs up.

  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: problem with msleep

    Don't put your GUI thread into sleep, use QTimer instead.

  3. #3
    Join Date
    Dec 2007
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with msleep

    Thanks.

    This is what i did and it works with qmake 4.3:
    Qt Code:
    1. void Labirynt::oncemore()
    2. {
    3. loop++;
    4. Generate();
    5. update();
    6. }
    7.  
    8. void Labirynt::Generate()
    9. {
    10. QTimer *timer = new QTimer(this);
    11. connect(timer, SIGNAL(timeout()), this, SLOT(oncemore()));
    12.  
    13. //mathematical calculations (these are changing variables which are used in
    14. // Labirynt::paintEvent [this is why i use update();])
    15.  
    16. if(loop<120)
    17. timer->singleShot(100, this, SLOT(oncemore()));
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Reinexen; 27th December 2007 at 14:17. Reason: missing [code] tags

  4. #4
    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: problem with msleep

    It would be better if you had only one timer.

Similar Threads

  1. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08
  2. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.