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

QPrintDialog does not open on mac after showing dialog box

    XMLWordPrintable

Details

    • macOS
    • 26db7de13d5885067844532b5a5814181a0ddf16

    Description

      The QPrintDialog does not come up on the mac operating system like it does on the Linux and Windows operating system.

      I have a simple test case attached to this report.

      When the test printer button is pressed a basic dialog box pops up. Close the dialog box and then the print dialog box will flash on the screen but not stay up (on the mac operating system). If the exec for the QPrintDialog is called twice then the second call results in the QPrintDialog box being displayed. It looks like the QPrintDialog is receiving a signal it should not.

      I have tried this test case on my Mac and a friends and it exhibits the same behavior.

      On Mac OS X, when a QPrintDialog is used, a NSPrintPanel is used for a native print dialog. If you want a model print dialog (QPrintDialog::exec()), the method runModealWithPrintInfo is called:

      qprintdialog_mac.mm:311
      int rval = [printPanel runModalWithPrintInfo:ep->printInfo];
      

      NSPrintPanel does not run completely isolated though, and does report events to QApplication's event loops as you can see form this backtrace:

      0	DebugApplication::notify	main.cpp	22	0x100003ce7	
      1	QCoreApplication::notifyInternal	qcoreapplication.cpp	822	0x1016a5e28	
      2	QCoreApplication::sendSpontaneousEvent	qcoreapplication.h	234	0x10003b7e5	
      3	QApplication::setActiveWindow	qapplication.cpp	2619	0x1000de28c	
      4	onApplicationWindowChangedActivation	qapplication_mac.mm	3074	0x10003325f	
      5	-[QCocoaWindowDelegate windowDidResignKey:]	qcocoawindowdelegate_mac.mm	321	0x10005a478	
      6	_nsnote_callback		0	0x7fff88a458ea	
      7	__CFXNotificationPost		0	0x7fff81bd3000	
      8	_CFXNotificationPostNotification		0	0x7fff81bbf578	
      9	-[NSNotificationCenter postNotificationName:object:userInfo:]		0	0x7fff88a3c84e	
      10	-[NSWindow resignKeyWindow]		0	0x7fff857ebb4f	
      11	-[NSWindow _changeKeyAndMainLimitedOK:]		0	0x7fff857324d4	
      12	-[NSWindow _makeKeyRegardlessOfVisibility]		0	0x7fff85732184	
      13	-[NSApplication _orderFrontModalWindow:relativeToWindow:]		0	0x7fff85976034	
      14	-[NSApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:]		0	0x7fff85975b6b	
      15	-[NSApplication beginModalSessionForWindow:]		0	0x7fff8597589c	
      16	-[NSApplication runModalForWindow:]		0	0x7fff859757be	
      17	-[NSPrintPanel runModalWithPrintInfo:]		0	0x7fff85ba748c	
      18	QPrintDialogPrivate::openCocoaPrintPanel	qprintdialog_mac.mm	311	0x1000bee9e	
      19	QPrintDialog::exec	qprintdialog_mac.mm	375	0x1000bf06b	
      20	PrintTest::mytest	main.cpp	253	0x100003c62	
      21	PrintTest::qt_static_metacall	moc_print.cpp	49	0x1000047ba	
      22	QMetaObject::activate	qobject.cpp	3574	0x1016c4a21	
      23	QAbstractButton::pressed	moc_qabstractbutton.cpp	207	0x1008e1fda	
      24	QAbstractButtonPrivate::emitPressed	qabstractbutton.cpp	560	0x10054e1cc	
      25	QAbstractButton::mousePressEvent	qabstractbutton.cpp	1096	0x10054e487	
      26	QWidget::event	qwidget.cpp	8326	0x10014bdff	
      27	QAbstractButton::event	qabstractbutton.cpp	1080	0x10054e6bd	
      28	QPushButton::event	qpushbutton.cpp	683	0x10061ca84	
      29	QApplicationPrivate::notify_helper	qapplication.cpp	4480	0x1000d3aed	
      30	QApplication::notify	qapplication.cpp	4023	0x1000d4ecc	
      31	DebugApplication::notify	main.cpp	30	0x100003f5d	
      32	QCoreApplication::notifyInternal	qcoreapplication.cpp	822	0x1016a5e28	
      33	QCoreApplication::sendSpontaneousEvent	qcoreapplication.h	234	0x10003b7e5	
      34	QApplicationPrivate::sendMouseEvent	qapplication.cpp	3136	0x1000db48d	
      35	qt_mac_handleMouseEvent	qt_cocoa_helpers_mac.mm	1267	0x100064d72	
      36	-[QCocoaView mouseDown:]	qcocoaview_mac.mm	550	0x100053bb0	
      37	-[NSWindow sendEvent:]		0	0x7fff8583634f	
      38	-[QCocoaWindow sendEvent:]	qcocoasharedwindowmethods_mac_p.h	183	0x10005822f	
      39	-[NSApplication sendEvent:]		0	0x7fff8576ba86	
      40	-[QNSApplication sendEvent:]	qcocoaapplication_mac.mm	183	0x10005e67e	
      41	-[NSApplication run]		0	0x7fff857024da	
      42	QEventDispatcherMac::processEvents	qeventdispatcher_mac.mm	615	0x10006bf82	
      43	QEventLoop::processEvents	qeventloop.cpp	149	0x1016a258a	
      44	QEventLoop::exec	qeventloop.cpp	204	0x1016a27dc	
      45	QCoreApplication::exec	qcoreapplication.cpp	1094	0x1016a67de	
      46	QApplication::exec	qapplication.cpp	3741	0x1000d7086	
      47	main	main.cpp	273	0x100003b95	
      

      Since event processing can occur by calling NSPrintPanel runModalWithPrintInfo, what is currently in the event queue is relevant. In this examples case, after QDialog::exec() closes these are the events not processed yet:

      notify :PrintTest WindowDeactivate-event (type-25) received
      notify :PrintTest ActivationChange-event (type-99) received
      notify :PrintTest FocusOut-event (type-9) received
      notify macintosh (aqua):QMacStyle FocusOut-event (type-9) received
      notify :PrintTest Paint-event (type-12) received
      notify print:QApplication ApplicationDeactivated-event (type-122) received
      

      So what happens is that when NSPrintPanel causes these events to be processed, it causes the NSPrintPanel to get closed.

      In this example, it is enough to call QApplication::processEvents() between basic.exec() and printDialog->exec() as it will clear the event queue before the NSPrintPanel is run, but this is just a work around to the large issue demonstrated here.

      Attachments

        1. main.cpp
          0.4 kB
        2. print.h
          0.3 kB
        3. print.pro
          0.0 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            richard Richard Moe Gustavsen
            cafun Jeff Franklin
            Votes:
            11 Vote for this issue
            Watchers:
            14 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes