Hi All,

I have a quick question:

I have a dir which has a huge number of files in it. I need to iterate through all the files and open them.

Qt Code:
  1. while (qdirIterator.hasNext())
  2.  
  3. {
  4. QString fileName = qdirIterator.next();
  5. QFileInfo fileInfo = qdirIterator.fileInfo();
  6.  
  7. QFile inFile( fileInfo.absoluteFilePath() );
  8.  
  9. if( !inFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
  10. {
  11. qCritical( "Failed to open file for reading." );
  12. return;
  13. }
  14. .
  15. .
  16. .
  17. } // while
To copy to clipboard, switch view to plain text mode 

First up when I look at this code I feel I am constructing too many QFile objects. So I want to do the following:

Qt Code:
  1. QFile inFile;
  2. while (qdirIterator.hasNext())
  3. {
  4. QString fileName = qdirIterator.next();
  5. QFileInfo fileInfo = qdirIterator.fileInfo();
  6.  
  7. if( !inFile.open( fileName, QIODevice::ReadOnly | QIODevice::Text ) )
  8. {
  9. qCritical( "Failed to open file for reading." );
  10. return;
  11. }
  12. .
  13. .
  14. .
  15. inFile.close();
  16. } // while
To copy to clipboard, switch view to plain text mode 

Problems with this are:

1. "QFile:: open" does not take QString as an argument.
2. And even if I manage to use "QFile:: open" in this manner the docs say, "When a QFile is opened using this function, close() does not actually close the file, but only flushes it."

So is there a workaround for 1. and also make sure that "QFile:: close()" actually closes the file and not just flush it?

Thanks in Advance,
sky.