Results 1 to 4 of 4

Thread: I'm printing blank pages with QWebView

  1. #1
    Join Date
    Jun 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Unhappy I'm printing blank pages with QWebView

    Hello everybody,

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

    Qt Code:
    1. Test::Test(QObject* parent):QObject(parent)
    2. {
    3. view = new QWebView;
    4. view->load(QUrl("page.html"));
    5. view->show();
    6. connect(view,SIGNAL(loadFinished(bool)),this,SLOT(loadFinished()));
    7. }
    8.  
    9. void Test::loadFinished()
    10. {
    11. qDebug()<<"load finished";
    12. QPrinter printer;
    13. QPrintDialog dialog(&printer);
    14. dialog.exec();
    15. view->print(&printer);
    16. }
    To copy to clipboard, switch view to plain text mode 


    Can any one help me with this problem
    Last edited by ihs280; 30th May 2011 at 16:03.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: I'm printing blank pages with QWebView

    Try QUrl::fromLocalFile() and make sure QFile::exits() returns true for the files you use.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3

    Default Re: I'm printing blank pages with QWebView

    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.

    Qt Code:
    1. void ChartViewer::onprintBtnClicked()
    2. {
    3. QString fileName = QFileDialog::getOpenFileName(this,"Open File",QString(),"Pdf File(*.png)");
    4. qDebug()<<"Print file name is "<<fileName;
    5. if(fileName.endsWith(".png"))
    6. {
    7. QPrinter printer;
    8. QWebView *view = new QWebView;
    9. QPrintDialog *dlg = new QPrintDialog(&printer,this);
    10. printer.setOutputFileName(fileName);
    11. if(dlg->exec() != QDialog::Accepted)
    12. return;
    13. view->load(fileName);
    14. view->print(&printer);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    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.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: I'm printing blank pages with QWebView

    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?

    Qt Code:
    1. QWebView *view = new QWebView;
    2. QPrintDialog *dlg = new QPrintDialog(&printer,this);
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 16th April 2014, 04:26
  2. Replies: 2
    Last Post: 14th April 2011, 17:37
  3. QWebView showing blank pages.
    By gontham in forum Qt Programming
    Replies: 1
    Last Post: 26th May 2010, 10:02
  4. QWebView not loading pages
    By magland in forum Qt Programming
    Replies: 0
    Last Post: 24th May 2008, 14:41
  5. QWizard with QWizardPages gives blank pages?
    By Tiansen in forum Qt Programming
    Replies: 4
    Last Post: 4th March 2008, 06:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.