title: How to save and load a QJsonDocument to a file?
body: <p>I am trying to learn how to use <strong>JSON</strong> and the <strong>Qt JSON classes</strong>. For example I wnat to create a simple <code>QJsonDocument</code>, save it to a file, load it into a different <code>QJsonDocument</code> and compare results.</p>
  
  <p>I managed to create a <code>QJsonDocument</code>. However there is no simple command in the <code>QJsonDocument</code> <a href="http://qt-project.org/doc/qt-5.0/qtcore/qjsondocument.html" rel="noreferrer">interface</a> to save it to a file. The same goes for <strong>loading</strong> the document from a file.</p>
  
  <pre><code>#include &lt;QJsonObject&gt;
  #include &lt;QJsonDocument&gt;
  #include &lt;QVariant&gt;
  
  int main()
  {
      QVariantMap map;
      map.insert("integer", 1);
      map.insert("double", 2.34);
      map.insert("bool", QVariant(true));
      map.insert("string", "word");
      QJsonObject object = QJsonObject::fromVariantMap(map);
  
      QJsonDocument document;
      document.setObject(object);
  
      // ?? save document to file
      // ?? load file to document
  
      return 0;
  }
  </code></pre>
  
  <p><a href="https://stackoverflow.com/a/18770335/1097451">This answer</a> shows how to load the document by</p>
  
  <ol>
  <li>reading to a <code>QFile</code></li>
  <li>converting <code>QFile</code> to a <code>QString</code></li>
  <li>converting the <code>QString</code> to a <code>QByteArray</code></li>
  <li>constructing the <code>QJsonDocument</code> from the <code>QByteArray</code></li>
  </ol>
  
  <p>Is there a more straightforward way to do this?</p>