QT 定时器详解

时间:2023-11-22 10:51:08

编译器 :   Qt Creator

在窗口化类中实现定时器

.h

#include <QTimer>
private slots:
  ...
    void onTimerOut();
private:
  ...
  QTimer *timer;

.cpp
RoomWindow::RoomWindow()
  {

    timer = new QTimer();
      timer->setInterval(5000);
      timer->start();
      connect(timer, SIGNAL(timeout()), this, SLOT(onTimerOut()));
}
void RoomWindow::onTimerOut()
{
    BufferMgr::getInstance()->getNetWorkObj()->sendGetRoomList();
}