Results 1 to 3 of 3

Thread: QThread Error Handling

  1. #1
    Join Date
    Feb 2010
    Location
    Pennsylvania, USA
    Posts
    36
    Thanks
    9
    Thanked 3 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QThread Error Handling

    Hi all,

    I'm starting to use QThreads to break some I/O and computationally intensive functions away from my GUI. I'm at the level of understanding that I know how to create/start/poll/destroy threads, and have inter-thread communication working. I'm now looking at error handling, but can't find any information--perhaps I'm wording my queries wrong?

    I have a function which would throw an exception upon encountering an error. This function is one I wish to move to its own thread. From what I can see, I can use inter-thread messaging to keep track of the thread's process, and if it quits before reaching "100%", then an error occurred, and I can derive the type from the percentage (the first 10% will be file read errors, etc.).

    But I don't want to implement anything before seeing if there is an "official" implementation of error handling for threads. If I can override QThread::run() to throw an exception, that's great, I wouldn't have to re-write some of my code. But If I have to use the above method, so be it. If anyone has any links to docs or examples, they'd be much appreciated. 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: QThread Error Handling

    I would recommend against QThread::run() throwing exceptions. You can throw an exception in some piece of code called from run() and catch it in run() but it is vital the exception doesn't "leak out" of run(). What I can recommend is that you simply emit a signal from your processing object and let that signal carry information about the error. There is really no need for exceptions here.

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

    TheJim01 (8th April 2010)

  4. #3
    Join Date
    Feb 2010
    Location
    Pennsylvania, USA
    Posts
    36
    Thanks
    9
    Thanked 3 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QThread Error Handling

    I use signals for reporting progress, so I don't know why I overlooked using them to report exceptions. Thank you very much!

Similar Threads

  1. Suggested Error Handling
    By Max Yaffe in forum Qt Programming
    Replies: 6
    Last Post: 15th July 2014, 17:29
  2. QWebPage error handling
    By Guilo in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2010, 05:48
  3. error with QList<my_labels *> handling
    By navid in forum Newbie
    Replies: 3
    Last Post: 4th November 2009, 14:29
  4. QNetworkReply error handling
    By timmu in forum Qt Programming
    Replies: 5
    Last Post: 25th August 2009, 09:07
  5. QThread event handling and QWaitCondition
    By mattc in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2009, 13:00

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.