C++,async异步
int Widget::asyncTask(int num) { qDebug() << "async thread id:" << QThread::currentThreadId(); this_thread::sleep_for(chrono::seconds(3)); return num * 10; } void Widget::fn_test_async() { /* * #include <future> * #include <thread> * using namespace std; */ qDebug() << "main thread id:" << QThread::currentThreadId(); future<int> future = async(std::launch::async, &Widget::asyncTask, this, 10); qDebug() << "run other function"; int ret = future.get(); qDebug() << "ret:" << ret; }


浙公网安备 33010602011771号