Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QFuture<void> detect exceptions

I was using a QFuture<void> with QtConcurrent::run to run some code in a background thread. I want to detect exceptions in this background code from the main thread.

According to Notification about exceptions in QtConcurrent::run exceptions are re-thrown when you request the result of the future. Unfortunately QFuture<void> does not have the result functions.

I can work around this by making my function return an int, then using QFuture<int> instead of QFuture<void> but adding a return value just to be able to detect exceptions seems a bit perverse.

Is there a way to detect exceptions with a QFuture<void>?

like image 427
plugwash Avatar asked Sep 18 '25 06:09

plugwash


1 Answers

Yes, while the QFuture<void> does not have a "result()" function it does have a "waitForFinished()" function that can be used for this purpose.

like image 57
plugwash Avatar answered Sep 20 '25 21:09

plugwash