简体   繁体   中英

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>?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM