#include <QCoreApplication> #include <QtDebug> #include <QThread> #include <thread> using namespace std; class Calculation { public: Calculation() { } //============================================= int Add(int a,int b) { qDebug()<<"working"<<a+b; QThread::msleep(1000); qDebug()<<"done ..."; return a+b; } }; int DOCalc(int a,int b) { qDebug()<<"working"<<a+b; QThread::msleep(1000); qDebug()<<"done ..."; return a+b; } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Calculation p; std::thread thr(DOCalc,1,2); auto future = std::async(&Calculation::Add,&p, 5,6); int res=future.get(); thr.join(); qDebug()<<"call after"<<res; return a.exec(); }
There was an error while loading. Please reload this page.