title: How to print pdf file in Qt
body: <p>I have tried to write some code to print a pdf file using Qt but somehow it's not working.
  If anybody has any idea to solve this problem, please provide your tips.</p>
  
  <pre><code>void ChartViewer::onprintBtnClicked(){ 
      String filename = QFileDialog::getOpenFileName(this,"Open File",QString(),"Pdf File(*.pdf)"); 
      qDebug()&lt;&lt;"Print file name is "&lt;&lt;filename; 
      if(!filename.isEmpty()) { 
          if(QFileInfo(filename).suffix().isEmpty()) 
              filename.append(".pdf"); 
  
          QPrinter printer(QPrinter::HighResolution);         
          printer.setOutputFormat(QPrinter::PdfFormat);  
          printer.setOutputFileName(filename);
          QPrintDialog*dlg = new QPrintDialog(&amp;printer,this); 
  
          if(textedit-&gt;textCursor().hasSelection()) 
              dlg-&gt;addEnabledOption(QAbstractPrintDialog::PrintSelection); 
  
          dlg-&gt;setWindowTitle(tr("Print Document")); 
  
          if(dlg-&gt;exec() == QDialog::Accepted) { 
              textedit-&gt;print(&amp;printer); 
          } 
  
          delete dlg; 
      } 
  }
  </code></pre>