QTimer::singleShot(2000, &a, SLOT(f()));
No such slot QCoreApplication::f() in ...
class tmr{public: void shot() { QTimer::singleShot(2000, NULL, SLOT(quit())); }};
tmr::shot();
#include <QtCore/QCoreApplication>#include <QTimer>#include <iostream>class tmr{public: void shot() { QTimer::singleShot(2000, QCoreApplication::instance(), SLOT(f())); }public slots: void f();};void tmr::f(){ std::cout << "display test string";}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); tmr s; s.shot(); return a.exec();}
QCoreApplication::instance()
class tmr{ Q_OBJECTpublic: void shot() { QTimer::singleShot(2000, this, SLOT(f())); }public slots: void f();};
QTimer::singleShot(2000, this, SLOT(f()));
class tmr : public QObject{ Q_OBJECTpublic: void shot() { QTimer::singleShot(2000, this, SLOT(f())); }public slots: void f();};
#include <QtCore/QCoreApplication>#include <QTimer>#include <QObject>#include <iostream>class Tmr : public QObject{ Q_OBJECTpublic: Tmr() { QTimer::singleShot(2000, this, SLOT(shot())); }public slots: void shot();};void Tmr::shot(){ std::cout << "display test string";}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); //Tmr s; //s.shot(); return a.exec();}
Tmr s;s.shot();
#include <QtCore/QCoreApplication>#include <QTimer>#include <QObject>#include <iostream>class Tmr : public QObject{ Q_OBJECTpublic: Tmr() { QTimer::singleShot(2000, this, SLOT(shot())); }public slots: void shot();};void Tmr::shot(){ std::cout << "display test string";}#include "tmr.moc"int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); Tmr s; s.shot(); return a.exec();}
#include <QtCore/QCoreApplication>#include <modul.h>#include <iostream>void Tmr::shot(){ std::cout << "display test string";}void Tmr::atimer(int msec){ QTimer::singleShot(msec, this, SLOT(shot()));}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); Tmr tobj; tobj.atimer(10000); return a.exec();}
#ifndef MODUL_H#define MODUL_H#include <QObject>#include <QTimer>class Tmr : public QObject{ Q_OBJECTpublic: Tmr() { }public slots: void shot(); void atimer(int msec);};#endif // MODUL_H