Results 1 to 7 of 7

Thread: get status of QRunnable

  1. #1
    Join Date
    Jul 2012
    Posts
    40
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default get status of QRunnable

    Hi I have a question ; )...

    I want to use QThreadPool to run several QRunnble Tasks concurrent.

    f.e. There is a machine with 8 cpu's.
    I want to start 8 Runnbles. But after 5 seconds my mainthread want to know the status of each runnable.

    t1: 10% finished
    t2: 70% finished
    and so on....

    What is the easiest approach to query a member of a QRunnable, while executing?


    thanks in advance

  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: get status of QRunnable

    How exactly would the runnable know if it is at 10% or 90% of its work?
    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
    Jul 2012
    Posts
    40
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: get status of QRunnable

    Thank you for your reply...

    Because there is a loop in the run method and I know the count.

  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: get status of QRunnable

    Then emit a signal and catch it somewhere or store the status in some member variable (possibly of type QAtomicInt) of the runnable object and read it from there.
    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. #5
    Join Date
    Jul 2012
    Posts
    40
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: get status of QRunnable

    But storing the status in a member of normal type int is not possible? Is this right?

    So I have to use QAtomicInt....

  6. #6
    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: get status of QRunnable

    Quote Originally Posted by Qtonimo View Post
    But storing the status in a member of normal type int is not possible? Is this right?
    You can store it however you like.
    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.


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

    Qtonimo (30th July 2012)

  8. #7
    Join Date
    Jul 2012
    Posts
    40
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: get status of QRunnable

    Ok, this works very well. So a getter method is possible between different threads.

    But why you recommended QAtomicInt?

Similar Threads

  1. Use QRunnable without QThreadPool
    By Qiieha in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2011, 10:02
  2. How to emit signals from QRunnable?
    By mlheese in forum Newbie
    Replies: 1
    Last Post: 29th July 2010, 23:26
  3. Replies: 3
    Last Post: 8th July 2010, 07:41
  4. QRunnable - how to cancel execution?
    By TorAn in forum Qt Programming
    Replies: 1
    Last Post: 3rd March 2010, 19:11
  5. QThreadPool and QRunnable
    By jimc1200 in forum Qt Programming
    Replies: 3
    Last Post: 6th May 2009, 10:43

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.