diff --git src/corelib/global/global.pri src/corelib/global/global.pri index dbd042b..295ff58 100644 --- src/corelib/global/global.pri +++ src/corelib/global/global.pri @@ -13,6 +13,9 @@ SOURCES += \ global/qmalloc.cpp \ global/qnumeric.cpp +OBJECTIVE_SOURCES += global/qtmessagebox.mm +LIBS += -framework AppKit + # qlibraryinfo.cpp includes qconfig.cpp INCLUDEPATH += $$QT_BUILD_TREE/src/corelib/global diff --git src/corelib/global/qglobal.cpp src/corelib/global/qglobal.cpp index 5b63952..789087a 100644 --- src/corelib/global/qglobal.cpp +++ src/corelib/global/qglobal.cpp @@ -2419,6 +2419,14 @@ void qt_message_output(QtMsgType msgType, const char *buf) tmp.Copy(ptr.Left(len)); // Panic the current thread. We don't use real panic codes, so 0 has no special meaning. User::Panic(tmp, 0); +#elif defined(Q_OS_MACX) && !defined(QT_BOOTSTRAPPED) + QString contextBuf = buf; + extern int qt_fatal_message_box(const QString&, const QString&); + if (qt_fatal_message_box("Qt fatal error", contextBuf)) { + abort(); + } else { + exit(1); + } #elif (defined(Q_OS_UNIX) || defined(Q_CC_MINGW)) abort(); // trap; generates core dump #else diff --git src/corelib/global/qtmessagebox.mm src/corelib/global/qtmessagebox.mm new file mode 100644 index 0000000..cb3ff4a --- /dev/null +++ src/corelib/global/qtmessagebox.mm @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2015 René J.V. Bertin +** +** This file is an extension of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "qstring.h" + +#include + +class AutoReleasePool +{ +public: + AutoReleasePool(): pool([[NSAutoreleasePool alloc] init]) {} + ~AutoReleasePool() { [pool drain]; } + +private: + NSAutoreleasePool *pool; +}; + +int qt_fatal_message_box( const QString &title, const QString &message ) +{ + int (*_CGSDefaultConnection_p)(); + _CGSDefaultConnection_p = (int (*)()) dlsym(RTLD_DEFAULT, "_CGSDefaultConnection"); + if (!_CGSDefaultConnection_p) { + NSLog(@"qt_fatal_message_box(%@,%@): couldn't load _CGSDefaultConnection: %s", + [NSString stringWithCString:message.toUtf8() encoding:NSUTF8StringEncoding], + [NSString stringWithCString:title.toUtf8() encoding:NSUTF8StringEncoding], dlerror()); + } + if (_CGSDefaultConnection_p && (*_CGSDefaultConnection_p)()) { + AutoReleasePool pool; + NSAlert* alert = [[[NSAlert alloc] init] autorelease]; + NSString *msg, *tit; + @synchronized([NSAlert class]){ + [alert addButtonWithTitle:@"Exit"]; + [alert addButtonWithTitle:@"Abort"]; + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert setMessageText:@"" ]; + if( !(msg = [NSString stringWithCString:message.toUtf8() encoding:NSUTF8StringEncoding]) ){ + msg = [NSString stringWithCString:message.toLatin1() encoding:NSASCIIStringEncoding]; + } + if( !(tit = [NSString stringWithCString:title.toUtf8() encoding:NSUTF8StringEncoding]) ){ + tit = [NSString stringWithCString:title.toLatin1() encoding:NSASCIIStringEncoding]; + } + if( msg ){ + [alert setInformativeText:msg]; + } + else{ + NSLog( @"msg=%@ tit=%@", msg, tit ); + } + [[alert window] setTitle:tit]; + return NSAlertSecondButtonReturn == [alert runModal]; + } + } + return 0; +}