编译器 : 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();
}