#include <QApplication>
#include <QDebug>
#include <QFile>
#include <QTextStream>
#include <QString>
void WriteFile(QString fileName)
{
QFile file(fileName);
if(!file.open(QFile::WriteOnly | QFile::Text))
{
qDebug() << "could not open file for writing.";
return;
}
QTextStream out(&file);
QString text("Hello QT!\n");
out << text;
out.flush();
file.close();
}
void ReadFile(QString fileName)
{
QFile file(fileName);
if(!file.open(QFile::ReadOnly | QFile::Text))
{
qDebug() << "could not open file for reading.";
return;
}
QTextStream in(&file);
QString text = in.readAll();
qDebug() << text;
file.close();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString fileName("/home/zxw/Desktop/mytest/test.txt");
WriteFile(fileName);
ReadFile(fileName);
return a.exec();
}
#include <QDebug>
#include <QFile>
#include <QTextStream>
#include <QString>
void WriteFile(QString fileName)
{
QFile file(fileName);
if(!file.open(QFile::WriteOnly | QFile::Text))
{
qDebug() << "could not open file for writing.";
return;
}
QTextStream out(&file);
QString text("Hello QT!\n");
out << text;
out.flush();
file.close();
}
void ReadFile(QString fileName)
{
QFile file(fileName);
if(!file.open(QFile::ReadOnly | QFile::Text))
{
qDebug() << "could not open file for reading.";
return;
}
QTextStream in(&file);
QString text = in.readAll();
qDebug() << text;
file.close();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString fileName("/home/zxw/Desktop/mytest/test.txt");
WriteFile(fileName);
ReadFile(fileName);
return a.exec();
}