Important: Please read the Qt Code of Conduct -

[SOLVED] QAbstractButton::mousePressEvent Unstable Behavior - Plug-in Application

  • I implemented Qt as a GUI module inside an Adobe Illustrator Plugin for Mac OS X.

    Half of the time, after boot up, the button click results in successful click event delivery. Once successful, it never failed, until next application reboots. When fails, it always crashes on the first button click and crashes at the execution of QApplication::flush(); inside QAbstractButton::mousePressEvent(QMouseEvent *e) function from qabstracbutton.cpp.

    The following is code I written to instantiate QApplication and Qt GUI components to reside inside an container provided by Illustrator's API:
    GetPlatformWindow returns dlgHnd which is NSView of a GUI container.
    pEditWidget is a QWidget class containing a few QPushButton.
    SetNotifyProc calls Qt connect method to setup button click callback.
    At startup Illustrator application loads the following codes which reside in a dll module.
    int argc; char **argv=NULL;
    g->qtApp = new QApplication(argc, argv);
    AIPanelPlatformWindow dlgHnd = NULL;
    sAIPanel->GetPlatformWindow(this->fPanel, dlgHnd);
    g->pEditWidget = new qtEditWidget();
    g->pEditWidget->sMenuItem->SetNotifyProc(g->pEditWidget->normalBtn, normalBtnClick);
    g->pEditWidget->sMenuItem->SetNotifyProc(g->pEditWidget->relativeBtn, relativeBtnClick);

    //set panel to contain qt stuffs
    NSView* newView = (NSView*)g->pEditWidget->winId();
    [dlgHnd setFrame:[newView frame]];
    [dlgHnd addSubview:newView];

    After show(), the application show the buttons. When fail, always break in this mousePressEvent() function at event flush() function (Code from Qt 4.8.5 source):

    void QAbstractButton::mousePressEvent(QMouseEvent e)
    if (e->button() != Qt::LeftButton) {
    if (hitButton(e->pos())) {
    d->pressed = true;
    repaint(); //flush paint event before invoking potentially expensive operation
    my note: after flush() EXE_BAD_ACCESS (code = 13, address = 0x0)
    } else {

    Here is the dump from within Xcode 4.6 in Thread 1:

    Thread 1, Queue :
    #0 0x000000011f68298d in QHashData::nextNode(QHashData::Node*) at /temp/qt4.8.5src/src/corelib/tools/qhash.cpp:294
    #1 0x000000011fa6f4d7 in QHash<QWidget*, QHashDummyValue>::const_iterator::operator++() at /temp/qt4.8.5src/src/gui/../../include/QtCore/../../src/corelib/tools/qhash.h:427
    #2 0x000000011fa6f510 in QSet<QWidget*>::const_iterator::operator++() at /temp/qt4.8.5src/src/gui/../../include/QtCore/../../src/corelib/tools/qset.h:155
    #3 0x000000011fa70b34 in QSet<QWidget*>::toList() const at /temp/qt4.8.5src/src/gui/../../include/QtCore/../../src/corelib/tools/qset.h:303
    #4 0x000000011fa59060 in QApplication::allWidgets() at /temp/qt4.8.5src/src/gui/kernel/qapplication.cpp:2180
    #5 0x000000011fa590a6 in QApplication::topLevelWidgets() at /temp/qt4.8.5src/src/gui/kernel/qapplication.cpp:2154
    #6 0x000000011f9b5900 in QEventDispatcherMac::flush() at /temp/qt4.8.5src/src/gui/kernel/
    #7 0x000000011f847f97 in QCoreApplication::flush() at /temp/qt4.8.5src/src/corelib/kernel/qcoreapplication.cpp:690
    #8 0x000000012029d4e4 in QAbstractButton::mousePressEvent(QMouseEvent*) at /temp/qt4.8.5src/src/gui/widgets/qabstractbutton.cpp:1097
    #9 0x000000011fb06b10 in QWidget::event(QEvent*) at /temp/qt4.8.5src/src/gui/kernel/qwidget.cpp:8385
    #10 0x000000012029d836 in QAbstractButton::event(QEvent*) at /temp/qt4.8.5src/src/gui/widgets/qabstractbutton.cpp:1082
    #11 0x00000001203f1c81 in QPushButton::event(QEvent*) at /temp/qt4.8.5src/src/gui/widgets/qpushbutton.cpp:683
    #12 0x000000011fa4fc62 in QApplicationPrivate::notify_helper(QObject*, QEvent*) at /temp/qt4.8.5src/src/gui/kernel/qapplication.cpp:4562
    #13 0x000000011fa5100a in QApplication::notify(QObject*, QEvent*) at /temp/qt4.8.5src/src/gui/kernel/qapplication.cpp:4105
    #14 0x000000011f84c9aa in QCoreApplication::notifyInternal(QObject*, QEvent*) at /temp/qt4.8.5src/src/corelib/kernel/qcoreapplication.cpp:953
    #15 0x000000011fa6f3d7 in QCoreApplication::sendSpontaneousEvent(QObject*, QEvent*) at /temp/qt4.8.5src/src/gui/../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:234
    #16 0x000000011fa61205 in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) at /temp/qt4.8.5src/src/gui/kernel/qapplication.cpp:3171
    #17 0x000000011f9ab812 in qt_mac_handleMouseEvent(NSEvent*, QEvent::Type, Qt::MouseButton, QWidget*, bool) at /temp/qt4.8.5src/src/gui/kernel/
    #18 0x000000011f99086a in -[QCocoaView mouseDown:] at /temp/qt4.8.5src/src/gui/kernel/
    #19 0x00007fff9255950e in -[NSWindow sendEvent:] ()
    #20 0x0000000105bfa558 in OWLRemoveObjCExceptionCallback ()
    #21 0x0000000105bfc961 in OWLRemoveObjCExceptionCallback ()
    #22 0x00007fff92555644 in -[NSApplication sendEvent:] ()
    #23 0x000000011f9a1646 in -[QNSApplication qt_sendEvent_replacement:] at /temp/qt4.8.5src/src/gui/kernel/
    #24 0x0000000108612145 in -[DVAMacApplication sendEvent:] ()
    #25 0x0000000108e981cc in -[ExoMacApplication sendEvent:] ()
    #26 0x00007fff9246b21a in -[NSApplication run] ()
    #27 0x0000000108e96807 in exo::app::OS_AppBase::RunEventLoop() ()
    #28 0x000000010075b698 in 0x10075b698 ()
    #29 0x00000001006ff385 in 0x1006ff385 ()
    #30 0x00000001006ef5d4 in 0x1006ef5d4 ()
    #31 0x00000001001635f8 in 0x1001635f8 ()

    This problem is repeatable and happens frequently (after few application boot ups).

    Any help would be appreciated.

    [edit: added coding tags @ SGaist]

  • The problem was not to wrap UI components with QWidget but with QMacNativeWidget. So, this problem is solved.

Log in to reply