#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog {
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
protected:
void changeEvent(QEvent *e);
void timerEvent(QTimerEvent *);// 定时器事件
void readFileToCtrl();
private:
Ui::Dialog *ui;
int theTimerId;
QString fileName;
};
#endif // DIALOG_H
// 以下是 CPP 文件
#include "dialog.h"
#include "ui_dialog.h"
#include <QFile>
#include <QMessageBox>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
theTimerId = this->startTimer(2 * 1000);// 间隔时间 2 秒
fileName = tr("c:/a.txt");// 要读取的文件
readFileToCtrl();
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
// 定时器相应代码
vo
Qt::定时读取文件
最新推荐文章于 2024-01-19 11:03:04 发布