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

Print: Preview.app opens before pdf is created

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.1
    • Fix Version/s: None
    • Component/s: GUI: Printing
    • Labels:
      None
    • Platform/s:
      macOS

      Description

      I guess with the fixes for QTBUG-25383 the following code makes it to qprintdialog_mac.mm

      - (void)printPanelDidEnd:(NSPrintPanel *)printPanel
              returnCode:(int)returnCode contextInfo:(void *)contextInfo
      {
      ...
       else if (dest == kPMDestinationPreview) {
                  static QTemporaryDir printPreviews;
                  auto documentName = printer->docName();
                  if (documentName.isEmpty())
                      documentName = QGuiApplication::applicationDisplayName();
                  auto fileName = printPreviews.filePath(QString(QLatin1String("%1.pdf")).arg(documentName));
                  printer->setOutputFileName(fileName);
                  // Ideally we would have a callback when the PDF engine is done writing
                  // to the file, and open Preview in response to that. Lacking that, we
                  // use the quick and dirty assumption that the the print operation will
                  // happen synchronously after the dialog is accepted, so we can defer
                  // the opening of the file to the next runloop pass.
                  dispatch_async(dispatch_get_main_queue(), ^{
                      [NSWorkspace.sharedWorkspace openFile:fileName.toNSString()];
                  });
              }
      ...
      }

      Well, your assumption can be wrong and lets preview.app open with error, because the pdf creation isn't finished.

      Our Apps needs the information of the printdialog before the painting begins (one-sided, two-sided, paper-format, etc. ). There are many sites to be painted and printed (so we use progressbars and stuff) in one operation and  - surprise - the main_queue finds time to proceed [NSWorkspace.sharedWorkspace openFile]. Specially if the Mac is one of the quicker ones. And there is absolut nothing I can do in my code to workaround this behavior. 

      I had to revet this 5.15 - changes in qprintdialog_mac.mm to Qt 5.12. (And the changes in qprinter.cpp, so that a choosen kPMDestinationPreview works with no installed printers).

       

       

       

        Attachments

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

          Activity

            People

            Assignee:
            johnlayt John Layt
            Reporter:
            bidi Brigitte Dunsbach
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes