PDA

View Full Version : Qt4 + OSX: App Crash when starting application through Finder



tommyd
23rd April 2006, 02:20
Hi all!

I'm pretty new to Qt programming, and even more new to this forum! So, let me introduce myself first: My name is Thomas Keller and I'm participating on the monotone project (venge.net/monotone) by creating a cross-platform GUI named guitone for this SCM.

Now, early builds of this GUI work fine under Linux and Windows, but my local tests show that this is not the case under OSX 10.4.6 (Qt 4.1.2). In detail:

The app is compiled perfectly, qmake creates an *.app folder structure where it places the binary into guitone.app/Contents/MacOS/guitone. When I try to start the application through the Finder though (or by using the 'open' command from the shell), the application crashes almost immediately (crash log follows).
Now, the weird thing is that this does NOT happen if I change via the shell into that subdirectory and start the application unix-alike with ./guitone or Contents/MacOS/guitone. Though, if I do $ guitone.app/Contents/MacOS/guitone (or above) it crashes likewise it does when starting it via "open", additionally it outputs "bus error" on console.

Has anybody a clue what am I doing wrong?

Thanks in advance!

Thomas.

---

Date/Time: 2006-04-23 03:18:43.048 +0200
OS Version: 10.4.6 (Build 8I127)
Report Version: 4

Command: guitone
Path: bin/guitone.app/Contents/MacOS/guitone
Parent: bash [22259]

Version: ??? (???)

PID: 22747
Thread: 0

Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000

Thread 0 Crashed:
0 QtGui 0x02282780 QListData::size() const + 0 (icplusplus.c:28)
1 QtGui 0x021dab8c qt_mac_set_modal_state(OpaqueMenuRef*, bool) + 408 (icplusplus.c:28)
2 QtGui 0x021dc4a0 QMenuBar::macUpdateMenuBar() + 556 (icplusplus.c:28)
3 QtGui 0x0204a0b8 QApplicationPrivate::globalEventProcessor(OpaqueEv entHandlerCallRef*, OpaqueEventRef*, void*) + 8552 (icplusplus.c:28)
4 com.apple.HIToolbox 0x9321c794 DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 692
5 com.apple.HIToolbox 0x9321beec SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 372
6 com.apple.HIToolbox 0x9321bd68 SendEventToEventTargetWithOptions + 40
7 com.apple.HIToolbox 0x932230c8 ToolboxEventDispatcherHandler(OpaqueEventHandlerCa llRef*, OpaqueEventRef*, void*) + 704
8 com.apple.HIToolbox 0x9321c9e4 DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1284
9 com.apple.HIToolbox 0x9321beec SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 372
10 com.apple.HIToolbox 0x93222c8c SendEventToEventTarget + 40
11 QtGui 0x0204604c qt_mac_send_event(QFlags<QEventLoop::ProcessEventsFlag>, OpaqueEventRef*, OpaqueWindowPtr*) + 192 (icplusplus.c:28)
12 QtGui 0x0204f2bc QEventDispatcherMac::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 568 (icplusplus.c:28)
13 QtCore 0x013e84c4 QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 68 (icplusplus.c:28)
14 QtCore 0x013e87ac QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 140 (icplusplus.c:28)
15 QtCore 0x013eab78 QCoreApplication::exec() + 192 (icplusplus.c:28)
16 guitone 0x0000d114 main + 580 (main.cpp:41)
17 guitone 0x000056d8 _start + 348 (crt.c:272)
18 guitone 0x00005578 start + 60

Thread 0 crashed with PPC Thread State 64:
srr0: 0x0000000002282780 srr1: 0x000000000200f030 vrsave: 0x0000000000000000
cr: 0x24022288 xer: 0x0000000000000000 lr: 0x00000000021dab8c ctr: 0x0000000090bc8c70
r0: 0x00000000021dab80 r1: 0x00000000bfffef10 r2: 0x0000000001655ab0 r3: 0x0000000000000000
r4: 0x00000000ffffe989 r5: 0x0000000000000000 r6: 0x00000000ffffe989 r7: 0x0000000001655b00
r8: 0x0000000001655b00 r9: 0x0000000001655b00 r10: 0x0000000000000000 r11: 0x00000000ffffffff
r12: 0x0000000000000001 r13: 0x0000000000000002 r14: 0x0000000000000000 r15: 0x00000000a321c4f8
r16: 0x000000000161de90 r17: 0x00000000bffff350 r18: 0x0000000063757465 r19: 0x000000000000000e
r20: 0x000000000160a790 r21: 0x00000000ffffd96e r22: 0x0000000000000000 r23: 0x00000000bffff4c0
r24: 0x0000000000000000 r25: 0x00000000bfffef54 r26: 0x0000000001654b30 r27: 0x000000000000000e
r28: 0x0000000071756974 r29: 0x00000000016121b0 r30: 0x0000000000000000 r31: 0x00000000021da9fc
...

wysota
23rd April 2006, 09:45
You have a dangling pointer somewhere, probably due to using a relative path somewhere which obviously fails. Without seeing the code it is hard to pinpoint the exact reason.

tommyd
23rd April 2006, 13:26
Indeed, it is a problem with a relative path. This is my main function:

#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include "view/Guitone.h"

int main(int argc, char** argv)
{
QApplication app(argc,argv);

// try to find a suitable locale and setup translations
QString locale = QLocale::system().name();
QTranslator translator;
translator.load(QString("i18n/guitone_") + locale);
app.installTranslator(&translator);

// create and show the main window
Guitone *mainWnd = new Guitone();
mainWnd->show();

app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
return app.exec();
}

When I comment out the complete translation stuff, the app does not crash anymore (Weird that the app doesn't crash on other platforms if the translations are not found. The Qt docs state that there is always a fallback to the original strings).

Now, how can I can bring that back in? I managed it to copy the needed ressources via a script file to .app/Contents/MacOS/i18n and apparently the application picks them up (I can see the translation about a second long), but then it crashes again. Do I need to use absolute paths here? Unfortunately this is handled differently on every OS, I've found the following method for OSX:

_NSGetExecutablePath(path, &path_len)

Thanks in advance for your answers!

Thomas

jacek
23rd April 2006, 13:34
Try:
QString path( QCoreApplication::applicationDirPath() + "/i18n" );
// or QString path( QLibraryInfo::location( QLibraryInfo::TranslationsPath ) );
if( translator.load( "guitone_" + locale, path ) ) {
app.installTranslator( &translator );
}

tommyd
23rd April 2006, 14:59
This is my code - I now even set the file by hand, but the app still crashes:

QTranslator translator;
QString path = QCoreApplication::applicationDirPath() + "/i18n";
if (translator.load("guitone_de.qm", path))
{
app.installTranslator(&translator);
}

Could it be that the translation file is somehow flawed? I create it as usual doing a call to lrelease, but still... any ideas?

Thanks,
Tommy.

tommyd
24th April 2006, 15:42
I've disabled loading translations for OSX in the meantime. If anybody knows a resolution for this problem, please let me know. Either here or http://developer.berlios.de/bugs/?func=detailbug&bug_id=7270&group_id=6547

Thanks,
Tommy.