title: How to print text in Qt when a button is clicked
body: <p>I have been reading the Qt documentation for QPrinter and QPrintDialog but I cannot figure how to print the contents in a textEdit field.</p>
  
  <p>Here is the code I have been try and which of course doesn't work.</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  #include &lt;QDebug&gt;
  #include &lt;QtPrintSupport/QPrinter&gt;
  #include &lt;QtPrintSupport/QPrintDialog&gt;
  #include &lt;QPainter&gt;
  
  
  void MainWindow::on_pushButton_clicked()
  {
      QString textFromField = ui-&gt;textEdit-&gt;toPlainText();
  
      QPrinter printer;
  
      QPrintDialog *printDialog = new QPrintDialog(&amp;printer, this);
  
      printDialog-&gt;setWindowTitle("Print Document");
  
      if(printDialog-&gt;exec() != QDialog::Accepted)
      {
  
      }
  
      QPainter painter;
      painter.begin(&amp;printer);
      painter.drawText(100, 100, 500, 500,Qt::AlignLeft | Qt::AlignTop, textFromField);
      painter.end();
  }
  </code></pre>
  
  <p>This is the output I get when I run it.</p>
  
  <blockquote>
    <p>:-1: warning: directory not found for option
    '-F/Applications/Qt5.1.0//5.1.0/clang_64/qtbase/lib' :-1: error:
    symbol(s) not found for architecture x86_64</p>
  </blockquote>
  
  <p>Any idea what am I doing wrong? Again all I want is to print the contents in a textEdit field.</p>