title: QFile/FILE* : How to properly close the handle?
body: <p>I need to open files with <code>QFile</code> and <code>QString</code> for multilingual without hair pulling. But I also need to manage the data of those files through the <code>std::stream</code> API. As many suggest, I used <code>std::fstream stdFile(fdopen(qtFile.handle(), mode));</code> to do so.</p>
  
  <p>However I hit a problem when it recurring operations. After a specific amount of file handling, the application crashes.</p>
  
  <p>The following code can reproduce the crash:</p>
  
  <pre><code>int fileOperationCount = 0;
  while (true)
  {
      QFile qtFile("plop.txt");
      qtFile.open(QIODevice::ReadOnly);
      std::ifstream file = std::ifstream(fdopen(qtFile.handle(), "rb"));
  
      if (!file.good())
          throw std::exception();
      file.seekg(0, file.beg);
      if (!file.good())
          throw std::exception(); //Will ALWAYS trigger at fileOperationCount = 509
  
      qtFile.close();
  
      fileOperationCount++;
  }
  </code></pre>
  
  <p>The 509th will crash after the <code>seekg</code>. It also happens if I were to manipulate hundreds of different files. It will still crash the 509th time I try to read a file, any file.</p>
  
  <p>Any idea what I'm doing wrong ?</p>