lyuts
26th April 2009, 13:19
Hi, guys.
I was just experimenting with QFile and reading a random file line by line and got this question. Here is what i tried
#include <QFile>
#include <QStringList>
#include <QtDebug>
int main(int argc, char *argv[])
{
QStringList list;
list << "Makefile";
QList<QString>::const_iterator it;
for (it = list.begin(); it != list.end(); ++it) {
QFile file((*it));
//file.setTextModeEnabled(true);
if (file.open(QFile::ReadOnly)) {
char buf[1024];
while ( 0 < file.readLine(buf, sizeof(buf)) ) {
qDebug() << buf;
}
file.close();
} else {
qDebug() << "main> Unable to open file " << (*it);
}
}
return 0;
}
Note that setTextMode is commented.
The i run the program and see the file printed line by line and it is ok.
But, if uncomment setTextMode line, compile this program and run it again i always get this error:
QFile::open: File (Makefile) already open
As far as i know the setTextMode set to true takes care of end-of-line conversion only.
Why does this happen?
Thanks.
I was just experimenting with QFile and reading a random file line by line and got this question. Here is what i tried
#include <QFile>
#include <QStringList>
#include <QtDebug>
int main(int argc, char *argv[])
{
QStringList list;
list << "Makefile";
QList<QString>::const_iterator it;
for (it = list.begin(); it != list.end(); ++it) {
QFile file((*it));
//file.setTextModeEnabled(true);
if (file.open(QFile::ReadOnly)) {
char buf[1024];
while ( 0 < file.readLine(buf, sizeof(buf)) ) {
qDebug() << buf;
}
file.close();
} else {
qDebug() << "main> Unable to open file " << (*it);
}
}
return 0;
}
Note that setTextMode is commented.
The i run the program and see the file printed line by line and it is ok.
But, if uncomment setTextMode line, compile this program and run it again i always get this error:
QFile::open: File (Makefile) already open
As far as i know the setTextMode set to true takes care of end-of-line conversion only.
Why does this happen?
Thanks.