You are not logged in.

Dear visitor, welcome to If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.


Wednesday, July 18th 2012, 4:52pm

Crash on launch with file on Mac

This is cross-posted from, but it's sat there for a while with no responses, so I'm hoping that somebody over here might have an idea.

I’m developing a desktop application, and I’m working on getting it to launch with a file from Finder on Mac OS X. I’ve subclassed the application object and overridden event() to handle the QFileOpenEvent, but every time I launch the app by double-clicking a file, it immediately crashes. This happens even if I don’t override event() at all, so it’s not a bug in my event handler. Of course, I can’t do this in the debugger, so I can’t tell exactly where it’s crashing, but the stack shown in Apple’s crash report looks like this (note that there are no stack frames within my application code).


Thread 0 Crashed: Dispatch queue:
0 QtCore 0x0000000100d671da QString::fromLocal8Bit(char const*, int) + 42
1 QtCore 0x0000000100e72dac QCoreApplication::arguments() + 124
2 QtGui 0x00000001000de8ef -[QCocoaApplicationDelegate application:openFiles:] + 223
3 0x00007fff805f3b52 -[NSApplication(NSAppleEventHandling) _handleAEOpenDocumentsForURLs:] + 505
4 0x00007fff804c0065 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 217
5 0x00007fff800f90d6 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 360
6 0x00007fff800f8f06 _NSAppleEventManagerGenericHandler + 114
7 0x00007fff82b1c32b aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned int, unsigned char*) + 162
8 0x00007fff82b1c224 dispatchEventAndSendReply(AEDesc const*, AEDesc*) + 32
9 0x00007fff82b1c12b aeProcessAppleEvent + 210
10 0x00007fff875ed619 AEProcessAppleEvent + 48
11 0x00007fff803c5095 _DPSNextEvent + 1191
12 0x00007fff803c4801 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
13 0x00007fff8038a68f -[NSApplication run] + 395
14 QtGui 0x00000001000e7c04 QEventDispatcherMac::processEvents(QFlags) + 1588
15 QtCore 0x0000000100e70774 QEventLoop::processEvents(QFlags) + 68
16 QtCore 0x0000000100e70a94 QEventLoop::exec(QFlags) + 180
17 QtCore 0x0000000100e720bc QCoreApplication::exec() + 188
18 com.blastedrock.MapMaker 0x0000000100003447 main + 46 (main.cpp:31)
19 com.blastedrock.MapMaker 0x00000001000032e0 start + 52

Anybody have any idea what’s going on? I’ve looked at the “browser” sample, which handles this event, and I don’t see anything that they’re doing differently than what I’m doing.
Thanks, Aaron


Wednesday, July 18th 2012, 5:33pm

Volker on qt-project found a solution for me. For posterity, it turns out that if you subclass QApplication you MUST accept argc by reference:

Source code

MyApplication::MyApplication(int &argc, char **argv);

If you don't, you'll get weird hard-to-reproduce crashes. Who knew?



Wednesday, July 18th 2012, 7:33pm

actually, I saw and diagnosed the same thing not long ago! That's what you get for passing temporaries into references - and yes it is hard to diagnose!
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.