[Qt, C++] Qt Timer 用法
#include <QtWidgets/QmainWIndow> #include <QObject> #include <QDebug> #include <QtCore> #include <QThread> class A : public QObject { Q_OBJECT public: GUI *gui; public slots: void GetTest1(); signals: void test1(); } void GetTest1() { std::cout << "test1" << std::endl; Sleep(10); } A *testA; QThread *threadA; int main() { testA = new A(); testA->moveToThread(threadA); threadA->start(); Qtimer *timer = new Qtimer(this); connect(timer, SIGNAL(timeout()), testA, SLOT(GetTest1())); timer->start(1000); }