QEventLoop loop;
QTimer timer;
int tryTimes = 3;
int currentTryRound = 0;
QObject::connect(&timer, &QTimer::timeout,[&](){
qDebug()<<"try your job here ,current try "<<(++currentTryRound)<<" times";
QCoreApplication::processEvents();
if ( currentTryRound > ( tryTimes - 1 ) ) {
loop.quit();
}
});
timer.start(1000); //interval 1000ms
loop.exec();
if (timer.isActive()) {
timer.stop();
}
Qt实现一个伪coroutine,应用场景while死循环尝试重连
最新推荐文章于 2024-02-03 19:24:46 发布