多线程可以提高Qt执行速度,尤其是Qt这种信号机制导致的可能变慢运行的情况下
QFuture<int> future = QtConcurrent::run(REngine::openFile, this, fileName);
QFutureWatcher<int> *watcher = new QFutureWatcher<int>();
watcher->setFuture(future);
m_open_file_watchers[watcher] = fileName;
connect(watcher, SIGNAL(finished()), this, SLOT(openFileFinished()));
QFuture维护了一个额外的线程去执行指定函数。
QFuture监听了多线程的结果返回。
QHash<QFutureWatcher<int>*, QString> m_open_file_watchers;
是存储返回结果的QHash对象