PDA

View Full Version : QWebView priting



mirag
25th February 2010, 09:45
Hi all!

For some time i've been trying to print contents of QWebView without blocking user interface.
(Using webView->print(printer) blocks UI for a very long amount of time)
My first though was to call print method from another thread.
Unfortunately the way i do it doesn't work.

The code I use:




class CPrintThread : public QRunnable {
//Q_OBJECT
private:
QWebView* m_v;
public:
CPrintThread(QWebView* view) {
m_v = view;
}
void run();
};


void CPrintThread::run() {

QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
QString printerName = "PDFCreator";
for (int i = 0 ; i < printers.size(); i++) {
QPrinterInfo printer = printers.at(i);
QString name = printer.printerName();
if ( name == printerName) {
QPrinter p(printer);
m_v->print(&p);
break;
}
}
}



I'm starting my thread that way:


CPrintThread* r = new CPrintThread(webView);
QThreadPool::globalInstance()->start(r);


Thx for any help