PDA

View Full Version : I'm printing blank pages with QWebView



ihs280
30th May 2011, 15:59
Hello everybody,

I'm trying to print a HTML page from QWebView but it always prints nothing but an
empty page


Test::Test(QObject* parent):QObject(parent)
{
view = new QWebView;
view->load(QUrl("page.html"));
view->show();
connect(view,SIGNAL(loadFinished(bool)),this,SLOT( loadFinished()));
}

void Test::loadFinished()
{
qDebug()<<"load finished";
QPrinter printer;
QPrintDialog dialog(&printer);
dialog.exec();
view->print(&printer);
}


Can any one help me with this problem

wysota
30th May 2011, 20:29
Try QUrl::fromLocalFile() and make sure QFile::exits() returns true for the files you use.

markjan1
16th August 2012, 20:51
I am trying to print an image file on printer using QWebview but instead of image blank page is printed. Please find the below code.


void ChartViewer::onprintBtnClicked()
{
QString fileName = QFileDialog::getOpenFileName(this,"Open File",QString(),"Pdf File(*.png)");
qDebug()<<"Print file name is "<<fileName;
if(fileName.endsWith(".png"))
{
QPrinter printer;
QWebView *view = new QWebView;
QPrintDialog *dlg = new QPrintDialog(&printer,this);
printer.setOutputFileName(fileName);
if(dlg->exec() != QDialog::Accepted)
return;
view->load(fileName);
view->print(&printer);
}
}

If I use view->show() then it has shown the image properly but printed page is coming blank. Request you to please look into the above code and correct me where I am doing wrong.

d_stranz
17th August 2012, 17:43
Request you to please look into the above code and correct me where I am doing wrong.

Including the two blatant memory leaks that happen every time the print button is clicked?



QWebView *view = new QWebView;
QPrintDialog *dlg = new QPrintDialog(&printer,this);