Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-140232

Crash when removing QWebEngineView while printing a document

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P1: Critical P1: Critical
    • None
    • 6.8.3, 6.9.2, 6.10.0 Beta4
    • None
    • Linux/Wayland, Linux/X11, macOS, Windows

      Description:
      If QWebEngineView is deleted while a document is being printed, the application crashes.

      Steps to Reproduce:

      1. Open a large document (e.g. a big PDF).
      2. Click the "Print" button.
      3. Start printing using view->print(printer).
      4. Delete the QWebEngineView before the printFinished signal is emitted. (e.g. by closing the window in the attached example)

      Expected Result:

      • Printing should stop gracefully, possibly with an error message in the console.

      Actual Result:

      • The application crashes.

      For example code with debug output:

       

      Widget::~Widget()
      {
          qDebug() << "~QWidget()";
          qDebug() << "printer state" << printer_->printerState();    
          
          printer_->abort(); // has no effect
      }
      
      void Widget::printRequested()
      {
          qDebug() << "create QPrinter";    
      
          printer_ = new QPrinter(QPrinter::HighResolution);
          printer_->setOutputFormat(QPrinter::PdfFormat);
          printer_->setOutputFileName("/tmp/printer_example.pdf");    
      
          connect(view_, &QWebEngineView::destroyed, this, [this]() {
              qDebug() << "destroy QPrinter";
              delete printer_;
          }, Qt::SingleShotConnection);    
      
          connect(view_, &QWebEngineView::printFinished, this, [](bool ok) {
              qDebug() << "print done with" << ok;
          }, Qt::SingleShotConnection);    
      
          view_->print(printer_);    
      
          qDebug() << "start printing" << printer_->printerState();
      } 

       

      Output:

       

      create QPrinter
      start printing 0
      ~QWidget()
      printer state 1
      destroy QPrinter
      QPaintDevice: Cannot destroy paint device that is being painted 
      .../webview_print_crash_test_001" terminated abnormally.

       

      Full minimal example

       webview_print_crash_test_001.tar.gz

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            moheim Moss Heim
            alekseydurachenko Aleksey Durachenko
            Votes:
            4 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes