Results 1 to 6 of 6

Thread: throwing exceptions across thread boundaries (using QtConcurrent)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: throwing exceptions across thread boundaries (using QtConcurrent)

    Thanks for your responses.
    I can now see that the code i posted can indeed not work as is.
    However shouldn't i be able to catch the exception when i use a QFuture with the QtConcurrent::run() and call future.result() in a slot connected to QFutureWatcher::finished() ?

    I tried to do this but it does not work either..

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: throwing exceptions across thread boundaries (using QtConcurrent)

    No, because it has no way of knowing you are calling it from a slot connected to finished. And even if it did, it still wouldn't make sense to thow an exception there, result() is only a getter and nothing bad can happen after finished() is signalled as there are no more threads performing the job.

  3. #3
    Join Date
    Sep 2011
    Posts
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: throwing exceptions across thread boundaries (using QtConcurrent)

    I have a similar problem with the following piece of code (Manager :: processPlugins is a valid method that receives 3 ints as parameters; the piece of code is inside a method that belongs to a Manager instance)

    1. QList<QFuture<void> > workers;
    2. int numWorkers = QThread::idealThreadCount();
    3. for( int worker = 0; worker < numWorkers; worker++ ){
    4. workers.push_back( QtConcurrent::run(
    5. this,
    6. &Manager :: processPlugins,
    7. worker,
    8. 2,
    9. 3);
    10. }
    11. for( int worker = 0; worker < workers.size(); worker++ ) {
    12. try {
    13. workers[worker].waitForFinished();
    14. } catch ( MyException& ex ) {
    15. printf( "Exception thrown\n" );
    16. }
    17. }


    However, when a MyException instance is thrown inside processPlugins, the catch block does not execute. Instead, the application terminates, and this warning appears:

    Qt Concurrent has caught an exception thrown from a worker thread.
    This is not supported, exceptions thrown in worker threads must be
    caught before control returns to Qt Concurrent

    Am I missing something?
    Thanks for any help

    Cheers,
    João Magalhães

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  2. Replies: 10
    Last Post: 20th March 2007, 22:19

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
  •  
Qt is a trademark of The Qt Company.