PDA

View Full Version : Read/Write console app



InterFiction
15th November 2011, 13:48
Hello,

I'm quite new to QT. I decided to start learning it after learning to do some console app programming. I'm still going through tutorials and what not. I've got a bit of code here, and I'm not sure what needs fixing.


#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QString>
#include <QFile>
#include <QTextStream>
#include <iostream>

using namespace std;

void Write(QString filename);
void Read (QString filename);


int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QString filename = "C:/myfile.txt";

Write(filename);
Read(filename);

return a.exec();
}

void Write(QString filename){

QFile mFile(filename);

if (!mFile.open(QFile::WriteOnly | QFile::Text )){

cout << "could not write file.";
return;

}
QTextStream out(&mFile);
cout << "hello world!!";
mFile.flush();
mFile.close();
}

void Read(QString filename){

QFile mFile(filename);
if (!mFile.open(QFile::ReadOnly | QFile::Text )){

cout << "could not open file for reading.";
return;

}
QTextStream in(&mFile);
QString mtext = in.readAll();
QDebug << mtext;

in << "hello world!!";
mFile.close();

}


the error is showing up on line 53.


error: expected unqualified-id before '<<' token

Oleg
15th November 2011, 14:00
qDebug() << mtext;