• QTimer 的使用


    QTimer(重复和单发计时器)

    应用 QTimer 时,先创建一个 QTimer 类,利用 connect 将 timeout() 与对应槽函数连接,在调用 start() 函数设置定时器时间间隔,每经过设置时间后,定时器会发出一个 timeout(),

    相应的槽函数就会被触发,直到调用 stop() 函数停止。
    举例:
      QTimer *timer = new QTimer(this);
      connect(timer,SIGNAL(timeout()),this,SLOT(function));
      timer->start(1000);

      也可以不用定义QTimer类,直接调用QTimer的成员函数singleShot(),定时器只执行一次
      QTimer::singleShot(1000,this,SLOT(updateCaption())); // 1秒后启动功能函数

    成员函数

    1)void QTimer::singleShot(int msec,Qt::TimerType timeType,const QObject *receiver,const *member) //在规定的时间间隔调用函数
    举例:
      #include
      #include

      int main(int argc,char *argv[])
      {
        QApplication app(argc,argv);
        QTimer::singleShot(10000,&app,SLOT(quit()));
        ........
        return app.exec();
      } //功能表述,在10秒钟后,应用程序将关闭

    2)void QTimer::start(int msec);
      启动或者重启服务器,msec 为时间间隔,没有参数时,时间间隔为 0

    3)void QTimer::stop();
      停止计时器

    4)void QTimer::timeout();
      当定时器时间到时,信号被发送

    5)int QTimer::timerID()
      返回正在运行的计时器的 ID 号,否则返回为 -1

  • 相关阅读:
    2018.4.23 深入理解java虚拟机(转)
    2018.4.23 git常用操作命令收集(转)
    2018.4.23 设计模式的一些总结
    2018.4.23 pip使用
    2018.4.23 git命令总结
    2018.4.23 git删除已经add的文件
    2018.4.17 VFS
    记北京第一次跳槽
    RocketMQ存储机制01-存储文件组织与内存映射
    将博客搬至CSDN
  • 原文地址:https://www.cnblogs.com/GyForever1004/p/9014787.html
Copyright © 2020-2023  润新知