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

Qt Code:
  1. #include <QFile>
  2. #include <QStringList>
  3.  
  4. #include <QtDebug>
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.  
  9. list << "Makefile";
  10.  
  11. QList<QString>::const_iterator it;
  12.  
  13. for (it = list.begin(); it != list.end(); ++it) {
  14.  
  15. QFile file((*it));
  16. //file.setTextModeEnabled(true);
  17.  
  18. if (file.open(QFile::ReadOnly)) {
  19.  
  20. char buf[1024];
  21.  
  22. while ( 0 < file.readLine(buf, sizeof(buf)) ) {
  23. qDebug() << buf;
  24. }
  25.  
  26. file.close();
  27.  
  28. } else {
  29. qDebug() << "main> Unable to open file " << (*it);
  30. }
  31. }
  32.  
  33. return 0;
  34. }
To copy to clipboard, switch view to plain text mode 

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:

Qt Code:
  1. QFile::open: File (Makefile) already open
To copy to clipboard, switch view to plain text mode 

As far as i know the setTextMode set to true takes care of end-of-line conversion only.

Why does this happen?

Thanks.