.h文件
.cpp文件
#include "timemainwindow.h"
#include "ui_timemainwindow.h"
#include <QTimer>
#include <QDebug>
TimeMainWindow::TimeMainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::TimeMainWindow)
{
ui->setupUi(this);
QTimer *timer=new QTimer(this);// 创建一个新的定时器
connect(timer,SIGNAL(timeout()),this,SLOT(mytimeSlot()));// 关联定时器的溢出信号到槽上
timer->start(3000);//开启三秒定时器
}
TimeMainWindow::~TimeMainWindow()
{
delete ui;
}
void TimeMainWindow::mytimeSlot()
{
QString text="我很帅";
qDebug()<<text;
}