Results 1 to 7 of 7

Thread: How to "sleep" inside QRunnable-derived class?

  1. #1
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to "sleep" inside QRunnable-derived class?

    In my QRunnable-derived class I need to "sleep" until external database operation is completed. How can I do that? QThread::sleep is protected static...

    Thanks.

  2. #2
    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: How to "sleep" inside QRunnable-derived class?

    But ::sleep() isn't.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to "sleep" inside QRunnable-derived class?

    Strange, I can't find this global function in Qt docs or in QThread class. Can you post the link to the doc or let me know where to look for ::sleep()?

  4. #4
    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: How to "sleep" inside QRunnable-derived class?

    It's not a Qt function. It's a POSIX.1-2001 function. I'm sure Windows has its own equivalent if it doesn't support it directly.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    TorAn (19th November 2009)

  6. #5
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to "sleep" inside QRunnable-derived class?

    I am surprised the there is no qt-way of doing it in platform-independent manner.
    Will this hack work?

    Qt Code:
    1. class mythreadhelper : public QThread
    2. {
    3. public:
    4. static void mysleep(int ms)
    5. {
    6. return sleep(ms);
    7. }
    8. };
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to "sleep" inside QRunnable-derived class?

    Considering QThread::sleep() calls ::Sleep, I'd have to say yes.

  8. #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: How to "sleep" inside QRunnable-derived class?

    Quote Originally Posted by TorAn View Post
    Will this hack work?
    It would be much easier if you just called ::Sleep() or ::sleep(). Or better yet if you used a wait condition.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 14th August 2009, 21:17
  2. Can not cast into the derived class from QScrollBar
    By learning_qt in forum Qt Programming
    Replies: 2
    Last Post: 19th December 2008, 10:23
  3. [SOLVED] Q_ENUMS from another class inside a plugin
    By desch in forum Qt Programming
    Replies: 1
    Last Post: 1st December 2007, 15:44
  4. rtti() of derived class
    By quickNitin in forum Newbie
    Replies: 4
    Last Post: 8th October 2006, 14:20
  5. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 07:36

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.