int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); classA a1; QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), &a1, SLOT(foo())); timer.start(200); return a.exec();}
class classA : public QObject{ Q_OBJECT int counter1, counter2; QTimer timer; public: classA() : counter1(0), counter2(0){} ~classA(){}public slots: void foo() { // ++counter1; qDebug() << counter1 << "FOO"; if(counter1 == 10) { timer.start(200); connect(&timer, SIGNAL(timeout()), this, SLOT(foo2())); QEventLoop lp; lp.exec(); } } void foo2() { // ++counter2; qDebug() << counter2 << "FOO2"; }};
C++ (Qt)void QEventDispatcherWin32Private::sendTimerEvent(int timerId){ WinTimerInfo *t = timerDict.value(timerId); if (t && !t->inTimerEvent) {