title: Copying a (rtf) table into the clipboard via QT (or: Writing a QTextDocument into clipboard)
body: <p>I need my QT application to create a table and copy this table into the clipboard, so that it can be pasted as table into libreoffice Writer or MS Word later.</p>
  
  <p>My first approach was to create html code for the table and insert it into the clipboard with</p>
  
  <pre><code>QClipboard *clipboard = QApplication::clipboard();
  QMimeData *mimeData = new QMimeData();
  mimeData-&gt;setData("text/html", html.toUtf8());
  clipboard-&gt;setMimeData(mimeData, QClipboard::Clipboard);
  </code></pre>
  
  <p>This approach didn't work. When pasting, the table cells where just appended to each other and inserted without formatting.</p>
  
  <p>My second approach using RTF:</p>
  
  <pre><code>QTextDocument rtfDocument;
  rtfDocument.setHtml(html);
  </code></pre>
  
  <p>But I found no way to copy this QTextDocument into the clipboard. Is there any?
  If I could get the RTF code out of the QTextDocument, I could use a way like</p>
  
  <pre><code>QClipboard *clipboard = QApplication::clipboard();
  QMimeData *mimeData = new QMimeData();
  mimeData-&gt;setData("text/rtf", rtfDocument.getCode());
  clipboard-&gt;setMimeData(mimeData, QClipboard::Clipboard);
  </code></pre>
  
  <p>But I also didn't find a function returning the rtf code.</p>
  
  <p>edit:</p>
  
  <p>With the last code box above I have a working way to copy rtf code into the clipboard. So any solution that can create RTF code representing a table would solve my problem.</p>