title: Reading entire file to QString
body: <p>I'm trying to read all the files in a folder, store them in <code>fileList</code> via <code>entryList()</code> and then, for each file in that folder, open it and read its contents into a <code>QString</code>. I think this should be easy, but I can't figure out what I'm doing wrong. The error I'm getting now says:</p>
  
  <p><code>no matching function for call to 'QTextStream::QTextStream(QFile*, QIODevice::OpenModeFlag)'</code></p>
  
  <p>I understand that this relates to the <em>wrong</em> way I'm declaring the <code>QTextStream</code>, but the thing is that examples I found seem to <em>DO</em> this, so, why can't I?</p>
  
  <p>Also, I noticed that if I add the test to check if the file open was successful, I get a warning saying "access denied", even if I'm just reading. Although, I can read the contents of the folder and even populate a <code>QListWidget</code> with those files with no problem.</p>
  
  <p>The fact that these are *.JSON files should not matter, right?</p>
  
  <p>I have seen <a href="https://stackoverflow.com/questions/2612103/qt-reading-from-a-text-file">this</a>, <a href="http://forrst.com/posts/Reading_a_file_into_a_string_with_QT-gW6" rel="noreferrer">this</a> and <a href="http://www.developer.nokia.com/Community/Wiki/How_to_read_data_from_a_file_in_Qt" rel="noreferrer">this</a> examples, but can't figure out what I'm doing wrong. Any help is appreciated.</p>
  
  <p>This is my code:</p>
  
  <pre><code>foreach(QString fileName, fileList){
  
      QFile file(fileName);
      file.open(QIODevice::ReadOnly);
      QString s;
  
      QTextStream s1(&amp;file, QIODevice::ReadOnly);
      s.append(s1.readAll());
  
      qDebug() &lt;&lt; "string content:" &lt;&lt; s; // empty!!!
  
  }
  </code></pre>
  
  <p><strong>UPDATE</strong>
  With the modification suggested by cmannett85, I no longer get the error, but for some reason the string <code>s</code> is still empty in the end.
  Regarding the read/write permissions in the folder, I have now noticed that if I test </p>
  
  <pre><code>if(!file.open(QIODevice::ReadWrite))
          {
              QMessageBox::information(0,"error",file.errorString());
          }
  </code></pre>
  
  <p>I get two warnings - I'm suspecting provoked by <code>.</code> and <code>..</code> - when I run the loop. Before it produced 32 warnings and I have 30 files inside the folder.
  Anyway, the files I'm trying to read are *.JSON and according to the properties dialog in Windows 7, they aren't set either as <em>read-only</em> or <em>hidden</em>. I can write files in the exact same folder with the same program.</p>
  
  <p>There is one thing that I wonder if could be the reason for this: the filename contains <code>.</code> before the extension, ie, <code>ID.file.16.json</code>.</p>
  
  <p><strong>UPDATE 2</strong>
  It is not related to the filename having <code>.</code> Tested it with different files and the result is the same.</p>
  
  <p>Also,the two warnings were indeed related to the <code>.</code> and <code>..</code>. <code>QDir::Filters</code> solved the problem. Curiously, though, should I apply the <code>QDir::Files</code> filter, everything is ok; but if I use the <code>QDir::NoDotAndDotDot</code> filter, no files are detected whatsoever, contrary to the Qt Assistant explanation that says that only these two elements are ignored using this filter.</p>
  
  <p><strong>UPDATE 3</strong></p>
  
  <p>Followed ddriver's suggestion, but still isn't working. Current code, including the retrieval of of the files in the folder is:</p>
  
  <pre><code>QDir assetsFolder = QDir("C:/Users/THB7OI/Desktop/app/qt-book/chap08/items");
  
  QStringList files = assetsFolder.entryList(QDir::Files);
  
      // for each file in the folder,
      foreach (QString file, files) {
          QFile f(file);
          if (!f.open(QFile::ReadOnly | QFile::Text)) break;
          QTextStream in(&amp;f);
          qDebug() &lt;&lt; f.size() &lt;&lt; in.readAll();
  
          f.close();
  
      }
  </code></pre>