title: QFile::flush() vs QFile::close()
body: <p>I am implementing a method in my class, which will write out data from a TableView Object to a CSV file. However when the program runs, the program writes the data to the file on a USB drive at a very slow rate(3 or 4 seconds), but works fine with the system's internal drive. Is this because i have not used flush() or close(), after writing the file ??</p>
  
  <p>Here is my code</p>
  
  <pre><code>bool ThicknessCalibrationDataDisplay::WriteCSVFileChanges()
  {
      QModelIndex tableViewModelindex =  tableViewModel_-&gt;index(0,0);
  
      QFile file(CSVFileName_);
      if(!file.exists())
          return false;
  
      if(!file.open(QIODevice::WriteOnly))
          return false;
  
  
      for(int i = 0; i &lt; totalRows_ ; i++)
      {
          for(int j = 0 ; j &lt; totalColumns_; j++)
          {
              tableViewModelindex =  tableViewModel_-&gt;index(i,j);
              qDebug()&lt;&lt;tableViewModelindex.data();
              QString text = tableViewModelindex.data().toString();
              QTextStream OutputStream(&amp;file);
  
              if(j == totalColumns_ - 1)
                  OutputStream&lt;&lt;"\n\r";
              else
                  OutputStream&lt;&lt;',';
  
          }
      }
  
  }
  </code></pre>
  
  <p>This was my code earlier, and now i plan to close the file stream, for a graceful exit.
  The Qt API for QFile::close() says</p>
  
  <blockquote>
    <p>Calls QFile::flush() and closes the file. Errors from flush are
    ignored.</p>
  </blockquote>
  
  <p>So should i just call close(), or is it better to call flush(), log any errors and then call close() ?</p>
  
  <p>Is there any other modification, that i have to make, to improve the write operation ?</p>