Obsolete Members for QTimer
QTimer 类的以下成员已被废弃。提供这些成员是为了确保旧源代码能够正常运行。我们强烈建议在新代码中不要使用它们。
静态公共成员
(deprecated in 6.8) void | singleShot(int msec, const QObject *receiver, const char *member) |
(deprecated in 6.8) void | singleShot(int msec, Qt::TimerType timerType, const QObject *receiver, const char *member) |
成员函数文档
[static, deprecated in 6.8] void QTimer::singleShot(int msec, const QObject *receiver, const char *member)
自 6.8 版本起,此函数已弃用。我们强烈建议不要在新代码中使用它。
请使用 `chrono` 的重载方法。此静态函数会在给定时间间隔后调用一个槽函数。
使用此函数非常方便,因为您无需处理 `timerEvent `,也无需创建本地 `QTimer ` 对象。
示例:
#include <QApplication>
#include <QTimer>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTimer::singleShot(600000, &app, QCoreApplication::quit);
//...
return app.exec();
}该示例程序将在10分钟(600,000毫秒)后自动终止。
receiver 是接收对象,member 是槽函数。时间间隔为msec 毫秒。
从 Qt 6.10 开始,设置负时间间隔将导致运行时警告,且该值会被重置为 1 毫秒。 在 Qt 6.10 之前,Qt Timer 虽然允许设置负间隔,但行为可能出人意料(例如,如果计时器正在运行则会停止,或者根本不会启动)。
注意:此函数是可重入的。
另请参阅 start()。
[static, deprecated in 6.8] void QTimer::singleShot(int msec, Qt::TimerType timerType, const QObject *receiver, const char *member)
自 6.8 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。
请使用 `chrono` 的重载方法。此静态函数会在指定的时间间隔后调用一个插槽。
使用此函数非常方便,因为您无需处理 `timerEvent `,也无需创建本地 `QTimer ` 对象。
receiver 是接收对象,member 是槽。时间间隔为msec 毫秒。timerType 会影响计时器的精度。
从 Qt 6.10 开始,设置负间隔会触发运行时警告,且该值将被重置为 1 毫秒。 在 Qt 6.10 之前,Qt Timer 虽然允许设置负间隔,但行为可能出人意料(例如,如果计时器正在运行则会停止,或者根本不会启动)。
这是一个重载函数。
注意:此函数是可重入的。
另请参阅 start()。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.