[static] void QTimer::singleShot(int msec, const QObject *receiver, const char *member)
这个静态函数在给定的时间间隔后调用一个槽。
使用此函数非常方便,因为不需要为 timerEvent 或创建本地 QTimer 对象而烦恼。
#include <QApplication>
#include <QTimer>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTimer::singleShot(600000, &app, SLOT(quit()));
...
return app.exec();
}
该示例程序在 10 分钟(600,000 毫秒)后自动终止。
receiver是接收对象,member是slot。时间间隔为 msec 毫秒。
singleShot 是单信号,只触发一次。如果想多次触发可以在槽函数中写循环。