title: Qt writting to xml: QIODevice::write (QFile, "D:/logs.xml"): device not open
body: <p>I am trying to save data to XML file in Qt. Everywhere is told that i need to write such kind of checking:</p>
  
  <pre><code>if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
  {
      qDebug() &lt;&lt; "Failed to open";
  }
  else
  {
      //write to file;
  }
  </code></pre>
  
  <p>I always get "failed to open" result. I just cannot find anything about it. If I don't use this checking I get this kind of error: QIODevice::write (QFile, "D:/logs.xml"): device not open. I just don't know what to do. Here is whole code what I was trying to use from tutorial:</p>
  
  <pre><code>QDomDocument document;
  // Making the root element
  QDomElement root = document.createElement("Dorms");
  
  // Adding the root element to the docuemnt
  document.appendChild(root);
  QFile file;
  file.setFileName("D:/logs.xml");
  if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
  {
      qDebug() &lt;&lt; "Failed to open";
  }
  else
  {
      QTextStream stream(&amp;file);
      stream &lt;&lt; document.toString();
      file.close();
      qDebug() &lt;&lt; "Done";
  }
  </code></pre>
  
  <p>Does anyone know what do I do wrong?</p>