title: Print a QWebView to PDF
body: <p>I want to print an QWebView to PDF and save it on the desktop.
  I implemented a function to do so, and here's the code:</p>
  
  <pre><code>// Print to PDF
  // Purpose: print incoming HTML source code to a PDF on the users desktop
  // Input:   string containing the HTML source code, string with the desired filename of resulting PDF
  // Output:  void
  void MainWindow::printToPDF(QString htmlinput, QString filename)
  {
      // Set location of resulting PDF
      QString saveLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/" + filename + ".pdf";
  
      // Initialize printer and set save location
      QPrinter printer(QPrinter::HighResolution);
      printer.setOutputFileName(saveLocation);
  
      // Create webview and load html source
      QWebView webview;
      webview.setHtml(htmlinput);
  
      // Create PDF
      webview.print(&amp;printer);
  }
  </code></pre>
  
  <p>Now my problem is that I get the following error in my application:</p>
  
  <pre><code>QPainter::begin(): Returned false
  </code></pre>
  
  <p>I coud confirm that this error is caused by the above function, on the other hand I tried above code solely in another project to confirm it works – which it does.</p>
  
  <p>Any suggestions?</p>