#include "widget.h"
#include <QFile>
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QTextStream>
#include <QString>
void Write(QString Filename)
{
QFile mFile(Filename);
if(!mFile.open(QFile::WriteOnly | QFile::Text))
{
qDebug() << "could not open file for write";
return;
}
QTextStream out(&mFile);
out << "hello world";
mFile.flush();
mFile.close();
}
void Read(QString Filename)
{
QFile mFile(Filename);
if(!mFile.open(QFile::ReadOnly | QFile::Text))
{
qDebug() << "could not open file for reading";
return;
}
QTextStream in(&mFile);
QString mText = in.readAll();
qDebug() << mText;
mFile.flush();
mFile.close();
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString mFilename("E:/qt_1029/test.txt");
Write(mFilename);
Read(mFilename);
return a.exec();
}