zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    变量1
    PHP 函数
    发送post请求
    XXE
    CSRF
    Html基础
    暴力破解
    Brup sute
    XSS
    URL 传参转义 (特殊符号转义)
  • 原文地址:https://www.cnblogs.com/GyForever1004/p/9014787.html
Copyright © 2011-2022 走看看