PDA

View Full Version : QFileDialog::getSaveFileName() issue on Max OS X 10.8



AndyBrice
19th October 2012, 13:15
This code puts up a standard platform file save dialog:



QString filters( "PDF (*.pdf);;PNG image (*.png);;JPEG image (*.jpg);;Bitmap image (*.bmp)" );
QString path = "/Users/abc/";
QString selectedFilter;
path = QFileDialog::getSaveFileName( NULL, "caption", path,
filters, &selectedFilter, QFileDialog::DontConfirmOverwrite );

it works fine on Windows and Mac OS X, except for Mac OS X 10.8 where it crashes the app if you click on the folder drop-down. The problem happens in both Qt 4.8.1 and 4.8.3.

The only way I can find around it is to pass the QFileDialog::DontUseNativeDialog flag, which is less than ideal.

So I created a tiny example app I could use to submit the bug report. But the example app works fine with the identical code!

Any ideas?

Andy Brice
http://www.successfulsoftware.net

8330

Added after 14 minutes:

BTW The crash stack trace is:


Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000003

VM Regions Near 0x3:
-->
__TEXT 0000000100000000-0000000100aa3000 [ 10.6M] r-x/rwx SM=COW /Users/USER/*/PerfectTablePlan.app/Contents/MacOS/PerfectTablePlan

Application Specific Information:
Performing @selector(qtDispatcherToQAction:) from sender NSMenuItem 0x1054ca500

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 ??? 0x0000000000000003 0 + 3
1 com.apple.FinderKit 0x00007fff8d6507ee ApplicationURL(TString const&) + 77
2 com.apple.FinderKit 0x00007fff8d650a27 AppBundleIDCanOpenExtension(TString const&, TString const&) + 392
3 com.apple.FinderKit 0x00007fff8d65114d ThisAppCanOpenExtension(TString const&) + 208
4 com.apple.FinderKit 0x00007fff8d65154f -[FIFinderViewGutsController finderLocationPopUpWillDisplay:] + 183
5 com.apple.FinderKit 0x00007fff8d67b7ff -[FILocationPopUp menuNeedsUpdate:] + 46
6 com.apple.AppKit 0x00007fff950266a8 -[NSMenu _populateFromDelegateWithEventRef:] + 674
7 com.apple.AppKit 0x00007fff94fcae64 -[NSMenu _populateWithEventRef:] + 83
8 com.apple.AppKit 0x00007fff950256ac -[NSCarbonMenuImpl _carbonPopulateEvent:handlerCallRef:] + 427
9 com.apple.AppKit 0x00007fff95025245 NSSLMMenuEventHandler + 342
10 com.apple.HIToolbox 0x00007fff9864cf0a DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1206
11 com.apple.HIToolbox 0x00007fff9864c3d9 SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 410
12 com.apple.HIToolbox 0x00007fff9864c236 SendEventToEventTargetWithOptions + 43
13 com.apple.HIToolbox 0x00007fff98695d58 SendMenuPopulate(MenuData*, OpaqueEventTargetRef*, unsigned int, double, unsigned int, OpaqueEventRef*, unsigned char*) + 279
14 com.apple.HIToolbox 0x00007fff9861ed5a SendMenuOpening(MenuSelectData*, MenuData*, double, unsigned int, unsigned int, __CFDictionary*, unsigned char, unsigned char*) + 286
15 com.apple.HIToolbox 0x00007fff987b3cff PopUpMenuSelectCore(MenuData*, Point, double, Point, unsigned short, unsigned int, Rect const*, unsigned short, unsigned int, Rect const*, Rect const*, __CFString const*, OpaqueMenuRef**, unsigned short*) + 895
16 com.apple.HIToolbox 0x00007fff987b3924 _HandlePopUpMenuSelection7 + 629
17 com.apple.AppKit 0x00007fff950a861b _NSSLMPopUpCarbonMenu3 + 3916
18 com.apple.AppKit 0x00007fff95409d2a _NSPopUpCarbonMenu3 + 39
19 com.apple.AppKit 0x00007fff950a75dc -[NSCarbonMenuImpl popUpMenu:atLocation:width:forView:withSelectedIte m:withFont:withFlags:withOptions:] + 346
20 com.apple.AppKit 0x00007fff9526b315 -[NSPopUpButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 540
21 com.apple.AppKit 0x00007fff94ef3c9c -[NSControl mouseDown:] + 820
22 com.apple.AppKit 0x00007fff94eeb60e -[NSWindow sendEvent:] + 6853
23 com.apple.AppKit 0x00007fff94ee7744 -[NSApplication sendEvent:] + 5761
24 QtGui 0x0000000101478352 -[QNSApplication sendEvent:] + 82
25 com.apple.AppKit 0x00007fff9505076a -[NSApplication _realDoModalLoop:peek:] + 582
26 com.apple.AppKit 0x00007fff950509ce -[NSApplication runModalForWindow:] + 120
27 com.apple.AppKit 0x00007fff9529bdb6 -[NSSavePanel runModal] + 302
28 QtGui 0x00000001014b2832 -[QNSOpenSavePanelDelegate runApplicationModalPanel] + 274
29 QtGui 0x00000001014b2e65 QFileDialogPrivate::_q_macRunNativeAppModalPanel() + 65
30 QtGui 0x0000000101917a97 QFileDialog::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) + 939
31 QtCore 0x00000001011e5951 QMetaObject::activate(QObject*, QMetaObject const*, int, void**) + 2001
32 QtCore 0x00000001011eba3b QSingleShotTimer::timerEvent(QTimerEvent*) + 53
33 QtCore 0x00000001011e49d9 QObject::event(QEvent*) + 51
34 QtGui 0x00000001014c6088 QApplicationPrivate::notify_helper(QObject*, QEvent*) + 304
35 QtGui 0x00000001014c6306 QApplication::notify(QObject*, QEvent*) + 600
36 PerfectTablePlan 0x000000010042721d TPApplication::notify(QObject*, QEvent*) + 227
37 QtCore 0x00000001011d0152 QCoreApplication::notifyInternal(QObject*, QEvent*) + 104
38 QtGui 0x00000001014c581a qt_sendSpontaneousEvent(QObject*, QEvent*) + 42
39 QtGui 0x0000000101480051 QEventDispatcherMacPrivate::activateTimer(__CFRunL oopTimer*, void*) + 193
40 com.apple.CoreFoundation 0x00007fff92e49da4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUN CTION__ + 20
41 com.apple.CoreFoundation 0x00007fff92e498bd __CFRunLoopDoTimer + 557
42 com.apple.CoreFoundation 0x00007fff92e2f099 __CFRunLoopRun + 1513
43 com.apple.CoreFoundation 0x00007fff92e2e6b2 CFRunLoopRunSpecific + 290
44 com.apple.HIToolbox 0x00007fff986740a4 RunCurrentEventLoopInMode + 209
45 com.apple.HIToolbox 0x00007fff98673d84 ReceiveNextEventCommon + 166
46 com.apple.HIToolbox 0x00007fff98673cd3 BlockUntilNextEventMatchingListInMode + 62
47 com.apple.AppKit 0x00007fff94e06613 _DPSNextEvent + 685
48 com.apple.AppKit 0x00007fff94e05ed2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
49 com.apple.AppKit 0x00007fff94dfd283 -[NSApplication run] + 517
50 QtGui 0x00000001014815c0 QEventDispatcherMac::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 840
51 QtCore 0x00000001011cd578 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 394
52 QtGui 0x0000000101915263 QDialog::exec() + 243
53 QtGui 0x000000010192811f QFileDialog::getSaveFileName(QWidget*, QString const&, QString const&, QString const&, QString*, QFlags<QFileDialog::Option>) + 361

In my example app (where it doesn't crash) it outputs:

2012-10-19 13:14:06.260 filedialog_crash[54235:707] *** WARNING: -[NSImage compositeToPoint:operation:] is deprecated in MacOSX 10.8 and later. Please use -[NSImage drawAtPoint:fromRect:operation:fraction:] instead.
2012-10-19 13:14:06.262 filedialog_crash[54235:707] *** WARNING: -[NSImage compositeToPoint:fromRect:operation:] is deprecated in MacOSX 10.8 and later. Please use -[NSImage drawAtPoint:fromRect:operation:fraction:] instead.

bruehl
13th November 2012, 22:38
I had the same crash in an native cocoa OSX program. An empty "Bundle Identifier" turned out to be the reason. After filling in my reverse web address and recompiling in Xcode it does not crash anymore.

hope it helps,
Rüdiger

christian.frisson
20th December 2012, 15:59
Actually, setting the bundle identifier didn't work out for me (Qt 4.8.3, OSX 10.8.2).

However I located the origin of the bug: the name filter(s)!

Let me propose a workaround from your example:


QStringList filenames;
QString filename;
QString path = "/Users/abc/";
QFileDialog dialog(0,"caption");
dialog.setDefaultSuffix("pdf");
dialog.setDirectory(path)
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setOption(QFileDialog::DontConfirmOverwrite );
if (dialog.exec())
filenames = dialog.selectedFiles();
if(filenames.size() == 1)
filename = filenames.first();


For me, both QFileDialog::setNameFilter and setNameFilters make the dialog crash when selecting the path from the drop-down menu in the dialog.

If you need many name filters, your only way out for now seems to be setting the option DontUseNativeDialog...

AndyBrice
20th June 2013, 11:47
I had the same crash in an native cocoa OSX program. An empty "Bundle Identifier" turned out to be the reason. After filling in my reverse web address and recompiling in Xcode it does not crash anymore.

hope it helps,
Rüdiger

Thanks, that was the info I needed. I just added:

<key>CFBundleIdentifier</key>
<string>com.oryxdigital.PerfectTablePlan</string>

To Info.plist and suddenly the crash seems to have gone away. I just need to test it a bit more now.

Thanks!

--
Andy Brice
http://www.perfecttableplan.com
http://www.successfulsoftware.net