一、QTimer类:
二、常用API:
// 构造函数// 如果指定了父对象, 创建的堆内存可以自动析构QTimer::QTimer(QObject *parent = nullptr);// 设置定时器时间间隔为 msec 毫秒// 默认值是0,一旦窗口系统事件队列中的所有事件都已经被处理完,一个时间间隔为0的QTimer就会触发void QTimer::setInterval(int msec);// 获取定时器的时间间隔, 返回值单位: 毫秒int QTimer::interval() const;// 根据指定的时间间隔启动或者重启定时器, 需要调用 setInterval() 设置时间间隔[slot] void QTimer::start();// 启动或重新启动定时器,超时间隔为msec毫秒。[slot] void QTimer::start(int msec);// 停止定时器。[slot] void QTimer::stop();// 设置定时器精度/*参数:- Qt::PreciseTimer -> 精确的精度, 毫秒级- Qt::CoarseTimer -> 粗糙的精度, 和1毫秒的误差在5%的范围内, 默认精度- Qt::VeryCoarseTimer -> 非常粗糙的精度, 精度在1秒左右*/void QTimer::setTimerType(Qt::TimerType atype);Qt::TimerType QTimer::timerType() const; // 获取当前定时器的精度// 如果定时器正在运行,返回true; 否则返回false。bool QTimer::isActive() const;// 判断定时器是否只触发一次bool QTimer::isSingleShot() const;// 设置定时器是否只触发一次, 参数为true定时器只触发一次, 为false定时器重复触发, 默认为falsevoid QTimer::setSingleShot(bool singleShot);
//当定时器超时时,该信号就会发出[signal] void QTimer::timeout();
/*功能: 在msec毫秒后发射一次信号, 并且只发射一次参数:- msec: 在msec毫秒后发射信号- receiver: 接收信号的对象地址- method: 槽函数地址*/[static] void QTimer::singleShot(int msec, const QObject *receiver,PointerToMemberFunction method);
三、
四、
