See this code:------>
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include<QFile>
#include<QString>
namespace Ui {
class Widget;
}
{
Q_OBJECT
public:
explicit Widget
(QWidget *parent
= 0);
~Widget();
public slots:
void updating();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include<QFile>
#include<QString>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
public slots:
void updating();
private:
Ui::Widget *ui;
QFile *file;
QString str;
};
#endif // WIDGET_H
To copy to clipboard, switch view to plain text mode
widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include<QTextStream>
ui(new Ui::Widget)
{
ui->setupUi(this);
file=new QFile("demo.txt");
str=stream.readAll();
}
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(updating()));
}
void Widget::updating(){
ui->lineEdit->setText(str);
}
Widget::~Widget()
{
delete ui;
}
#include "widget.h"
#include "ui_widget.h"
#include<QTextStream>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
file=new QFile("demo.txt");
if(file->open(QIODevice::ReadOnly)){
QTextStream stream(file);
str=stream.readAll();
}
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(updating()));
}
void Widget::updating(){
ui->lineEdit->setText(str);
}
Widget::~Widget()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Bookmarks