title: Save to HTML with QPlainTextEdit
body: <p>I am writing a Text Editor using the Qt C++ framework. I'm using a QPlainTextEdit as the central widget where the user writes out his document. The text can be bolded, italicised and coloured. </p>
  
  <p>I'm having a problem when it comes to writing the save method. I want to save the formatting, but all I've found is the toPlainText() function which obviously means that all the formatting is lost. How can I save the formatting?</p>
  
  <p>I've attached the code for my save function, just in case my question isn't clear:</p>
  
  <pre><code>bool TextEditor::saveDocument(QString filePath)
  {
      qDebug()&lt;&lt;"Saving File at"&lt;&lt;filePath&lt;&lt;endl;
      QFile document(filePath);
      if(!document.open(QFile::WriteOnly | QFile::Text))
      {
          qDebug()&lt;&lt;"An Error occur while opening "&lt;&lt;document.fileName()&lt;&lt;endl;
          return false;
      }
      QTextStream writer(&amp;document);
  
      writer &lt;&lt; ui-&gt;Editor-&gt;toPlainText();
      writer.flush();
      document.close();
      qDebug()&lt;&lt;"Document saved successfully.";
  
      if(this-&gt;document == NULL)
          this-&gt;setDocument(&amp;document);
  
      return true;
  }
  </code></pre>