動作する次のコードがあります(ただし、動作しないはずです)
void myfunction(){
auto future = function_which_return_future();
auto *watcher = new QFutureWatcher<VariantTable>;
QObject::connect(watcher,&QFutureWatcher<VariantTable>::finished,this,[=](){
VariantTable table = future.result();
// do some stuff
delete watcher;
});
watcher->setFuture(future);
}
このコードでは、future はスコープ外になりますが、watched のスロット内のコードは引き続き実行されます。
これは、物事があまりにも速く起こっているためであり、物事が遅くなるとコードが失敗する可能性がありますか? または、 QFutureWatcher::setFuture を呼び出した後、未来が必要ないというだけですか?