C++ 使用QFuture更新QProgressDialog
在等待QFuture时,主GUI线程更新QProgressDialog的正确方式是什么。具体来说,在这个循环中会发生什么:C++ 使用QFuture更新QProgressDialog,c++,qt,qt4,qtconcurrent,C++,Qt,Qt4,Qtconcurrent,在等待QFuture时,主GUI线程更新QProgressDialog的正确方式是什么。具体来说,在这个循环中会发生什么: QProgressDialog pd(...); QFuture f = ...; while (!f.isFinished()) { pd.setValue(f.progressValue()); // what goes here? } 现在我有一个类似sleep()的调用,但这并不是最优的(当然也会引入一些GUI延迟) 如果我什么也不放,主线程将循环po
QProgressDialog pd(...);
QFuture f = ...;
while (!f.isFinished()) {
pd.setValue(f.progressValue());
// what goes here?
}
现在我有一个类似sleep()的调用,但这并不是最优的(当然也会引入一些GUI延迟)
如果我什么也不放,主线程将循环pole pd.setValue(),浪费CPU周期
我希望放置类似于QCoreApplication::processEvents(标志,maxtime)的东西,但是如果事件队列为空,它会立即返回。我想要一个版本,等待,直到maxtime或任何东西,即使队列是空的。这样,我得到了延迟,主线程总是准备好响应GUI事件。使用信号和插槽来监视QFuture对象
QFutureWatcher watcher;
QProgressDialog pd(...);
connect(&watcher, SIGNAL(progressValueChanged(int)), &pd, SLOT(setValue(int)));
QFuture f = ...
watcher.setFuture(f);
回答得好,蒂姆。仅供参考,
connect(watcher,…)中的watcher
前面是否缺少一个&
代码>?