title: qt c++ QDialog open new file
body: <p>After almost a week of searching and reading qt documentation, I still can't figure out how to use QDialog to create a <em>NEW</em> file on my hard disk for writing data. I can open a file and write data if the file already exists, but if I attempt to create a NEW file, I get a message that the file does not exist. I can create a new file if I do not use QDialog by hard coding the path and file name, but would like to be able to choose the file location, and get the customary messages; for instance that the file already exists and asked if it is OK to overwrite it. Here is a snippet of my latest attempt:</p>
  
  <pre><code>void MainWindow::on_pushButton_3_clicked()
  {
      QString filename = QFileDialog::getOpenFileName(
              this,
              tr("Sensor data"),
              "C//",
              "Text File (*.txt)"
              );
      QFile file(filename);
      if (!file.open(QIODevice::ReadWrite))
      {
          QMessageBox::information(0,"info",file.errorString());
          return;
      }
      QTextStream out(&amp;file);
  
      out&lt;&lt;"string1";
      out&lt;&lt;"\n";
      out&lt;&lt;"string2";
      out&lt;&lt;"\n";
      out&lt;&lt;"string3";
      out&lt;&lt;"\n";
      out&lt;&lt;"string4";
      out&lt;&lt;"\n";
      out&lt;&lt;"string5";
      file.close();
  }
  </code></pre>
  
  <p>Can QDialog be used for this purpose? If not, please point me to information on how it is done.</p>
  
  <p>Thanks in advance!</p>