[ I realized I ought to supply the crash backtrace; I have appended it below my 
signature. ]

Hi folks.  I’m seeing something weird that I don’t understand.  I have a 
connection defined for the main window of my Qt Widgets app, like so:

   connect(qApp, &QApplication::focusChanged, [this]() { updateUIEnabling(); });

I’m seeing a 100% reproducible crash as a result of this.  When the 
focusChanged signal fires, I end up in updateUIEnabling() as expected, but I 
immediately crash because something about the state of things is corrupted; the 
immediate symptom, according to the debugger, is that the ui pointer for my 
main window is equal to 0x1 (yuck).  I try to access a button,  
ui->playOneStepButton, and it crashes.  As I said, 100% reproducible.

The weird thing is that this does *not* happen if I change the connect 
statement to this:

   connect(qApp, &QApplication::focusChanged, this, 
&QtSLiMWindow::updateUIEnabling);

Now, 100% of the time, there is no problem, no crash, and my app chugs along 
happily.  No other code changes involved.  I can literally flip this connect 
definition back and forth in my code and go from 100% crashing to 100% fine.

I’m pretty new to Qt and maybe I’m just being clueless somehow; but I thought 
that the two definitions above would be essentially identical in their effect.  
Why does the first one crash?  Note that it works fine in general; it seems to 
crash specifically when I open a *second* main window (which makes its own 
connection to focusChanged in the same way), and then close that second main 
window.  Now the first main window’s connection is somehow unhappy, and the 
next time I trigger the focusChanged() signal, boom.  It’s as if the connection 
for the second window somehow interferes with the connection for the first 
window, and closing the second window leads to a corruption in the connection 
state.

Naturally, I am now nervous about using the first type of connection anywhere 
in my code, since I don’t understand what the issue is.  Can anyone shed light 
on this?

Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University


Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   com.sticksoftware.QtSLiM            0x00000001003c84b1 
QtSLiMWindow::updateUIEnabling() + 17 (QtSLiMWindow.cpp:1589)
1   com.sticksoftware.QtSLiM            0x00000001003d224e 
QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, 
QtSLiMWindow::init()::$_3>::call(QtSLiMWindow::init()::$_3&, void**) + 14 
(qobjectdefs_impl.h:146)
2   org.qt-project.QtCore               0x000000010228ca95 void 
doActivate<false>(QObject*, int, void**) + 1157 (memory:2597)
3   org.qt-project.QtWidgets            0x00000001013d67de 
QApplicationPrivate::setFocusWidget(QWidget*, Qt::FocusReason) + 510
4   org.qt-project.QtWidgets            0x000000010140f6fd 
QWidget::setFocus(Qt::FocusReason) + 637 (qwidget.cpp:6356)
5   org.qt-project.QtWidgets            0x00000001013d7dd8 
QApplication::setActiveWindow(QWidget*) + 1160
6   org.qt-project.QtWidgets            0x00000001013d8333 
QApplicationPrivate::notifyActiveWindowChange(QWindow*) + 51 
(qapplication.cpp:2101)
7   org.qt-project.QtGui                0x0000000101a35623 
QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent*)
 + 675 (qguiapplication.cpp:2438)
8   org.qt-project.QtGui                0x0000000101a12cc3 bool 
QWindowSystemInterfacePrivate::handleWindowSystemEvent<QWindowSystemInterface::SynchronousDelivery>(QWindowSystemInterfacePrivate::WindowSystemEvent*)
 + 115 (qwindowsysteminterface.cpp:106)
9   libqcocoa.dylib                     0x00000001063511ee 
QCocoaWindow::windowDidBecomeKey() + 238 (qcocoawindow.mm:1194)
10  org.qt-project.QtCore               0x00000001022648d6 
QMetaMethod::invoke(QObject*, Qt::ConnectionType, QGenericReturnArgument, 
QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, 
QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, 
QGenericArgument, QGenericArgument) const + 1270
11  libqcocoa.dylib                     0x0000000106354830 invocation function 
for block in qRegisterNotificationCallbacks() + 1936 (qcocoawindow.mm:131)
12  com.apple.Foundation                0x00007fff3860cfab -[__NSObserver 
_doit:] + 296
13  com.apple.CoreFoundation            0x00007fff35f8c35f 
__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
14  com.apple.CoreFoundation            0x00007fff35f8c2f3 
___CFXRegistrationPost1_block_invoke + 63
15  com.apple.CoreFoundation            0x00007fff35f8c268 
_CFXRegistrationPost1 + 372
16  com.apple.CoreFoundation            0x00007fff35f8bebe 
___CFXNotificationPost_block_invoke + 97
17  com.apple.CoreFoundation            0x00007fff35f5b7e2 
-[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1575
18  com.apple.CoreFoundation            0x00007fff35f5ac82 _CFXNotificationPost 
+ 1351
19  com.apple.Foundation                0x00007fff385e0a22 
-[NSNotificationCenter postNotificationName:object:userInfo:] + 59
20  com.apple.AppKit                    0x00007fff3333675e -[NSWindow 
becomeKeyWindow] + 1276
21  com.apple.AppKit                    0x00007fff332b85ae -[NSWindow 
_changeKeyAndMainLimitedOK:] + 963
22  com.apple.AppKit                    0x00007fff332b80b2 -[NSWindow 
_makeKeyRegardlessOfVisibility] + 76
23  com.apple.AppKit                    0x00007fff332ab8d9 -[NSWindow 
makeKeyAndOrderFront:] + 40
24  libqcocoa.dylib                     0x000000010634d83d 
QCocoaWindow::setVisible(bool) + 1597 (qcocoawindow.mm:370)
25  org.qt-project.QtGui                0x0000000101a3d138 
QWindowPrivate::setVisible(bool) + 1112 (qwindow.cpp:410)
26  org.qt-project.QtWidgets            0x00000001014115f7 
QWidgetPrivate::show_sys() + 903 (qwidget.cpp:7910)
27  org.qt-project.QtWidgets            0x00000001014129e5 
QWidgetPrivate::show_helper() + 405 (qwidget.cpp:7833)
28  org.qt-project.QtWidgets            0x0000000101413626 
QWidgetPrivate::setVisible(bool) + 806 (qwidget.cpp:8129)
29  com.sticksoftware.QtSLiM            0x0000000100426d55 
QtSLiMEidosConsole::setVariableBrowserVisibility(bool) + 149 
(QtSLiMEidosConsole.cpp:221)
30  com.sticksoftware.QtSLiM            0x00000001003d1170 
QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void 
(QtSLiMAppDelegate::*)()>::call(void (QtSLiMAppDelegate::*)(), 
QtSLiMAppDelegate*, void**) + 32 (qobjectdefs_impl.h:152)
31  org.qt-project.QtCore               0x000000010228ca95 void 
doActivate<false>(QObject*, int, void**) + 1157 (memory:2597)
32  org.qt-project.QtWidgets            0x00000001014c271f 
QAbstractButtonPrivate::emitClicked() + 111 (qsharedpointer_impl.h:701)
33  org.qt-project.QtWidgets            0x00000001014c25b9 
QAbstractButtonPrivate::click() + 233 (qabstractbutton.cpp:409)
34  org.qt-project.QtWidgets            0x00000001014c36ef 
QAbstractButton::mouseReleaseEvent(QMouseEvent*) + 271 
(qabstractbutton.cpp:1013)
35  org.qt-project.QtWidgets            0x000000010141399d 
QWidget::event(QEvent*) + 445 (qwidget.cpp:8659)
36  org.qt-project.QtWidgets            0x00000001013d8f5a 
QApplicationPrivate::notify_helper(QObject*, QEvent*) + 266 
(qapplication.cpp:3687)
37  org.qt-project.QtWidgets            0x00000001013dbe32 
QApplication::notify(QObject*, QEvent*) + 7330 (qapplication.cpp:3129)
38  org.qt-project.QtCore               0x00000001022599f4 
QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212 
(qcoreapplication.cpp:1075)
39  org.qt-project.QtWidgets            0x00000001013d9880 
QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, 
QWidget**, QPointer<QWidget>&, bool, bool) + 896
40  org.qt-project.QtWidgets            0x0000000101432908 
QWidgetWindow::handleMouseEvent(QMouseEvent*) + 1704 (qwidgetwindow.cpp:673)
41  org.qt-project.QtWidgets            0x00000001014315f5 
QWidgetWindow::event(QEvent*) + 229 (qwidgetwindow.cpp:295)
42  org.qt-project.QtWidgets            0x00000001013d8f5a 
QApplicationPrivate::notify_helper(QObject*, QEvent*) + 266 
(qapplication.cpp:3687)
43  org.qt-project.QtWidgets            0x00000001013da3e6 
QApplication::notify(QObject*, QEvent*) + 598
44  org.qt-project.QtCore               0x00000001022599f4 
QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212 
(qcoreapplication.cpp:1075)
45  org.qt-project.QtGui                0x0000000101a32895 
QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent*)
 + 3397 (qguiapplication.cpp:2204)
46  org.qt-project.QtGui                0x0000000101a1815b 
QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>)
 + 219 (qwindowsysteminterface.cpp:1176)
47  libqcocoa.dylib                     0x00000001063690f0 
QCocoaEventDispatcherPrivate::processPostedEvents() + 320 
(qcocoaeventdispatcher.mm:890)
48  libqcocoa.dylib                     0x0000000106369858 
QCocoaEventDispatcherPrivate::postedEventsSourceCallback(void*) + 40
49  com.apple.CoreFoundation            0x00007fff35f96b21 
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
50  com.apple.CoreFoundation            0x00007fff35f96ac0 __CFRunLoopDoSource0 
+ 103
51  com.apple.CoreFoundation            0x00007fff35f968d4 
__CFRunLoopDoSources0 + 209
52  com.apple.CoreFoundation            0x00007fff35f95740 __CFRunLoopRun + 1272
53  com.apple.CoreFoundation            0x00007fff35f94bd3 CFRunLoopRunSpecific 
+ 499
54  com.apple.HIToolbox                 0x00007fff34aea65d 
RunCurrentEventLoopInMode + 292
55  com.apple.HIToolbox                 0x00007fff34aea2a9 
ReceiveNextEventCommon + 356
56  com.apple.HIToolbox                 0x00007fff34aea127 
_BlockUntilNextEventMatchingListInModeWithFilter + 64
57  com.apple.AppKit                    0x00007fff3315aba4 _DPSNextEvent + 990
58  com.apple.AppKit                    0x00007fff33159380 
-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] 
+ 1352
59  com.apple.AppKit                    0x00007fff3314b09e -[NSApplication run] 
+ 658
60  libqcocoa.dylib                     0x00000001063685d3 
QCocoaEventDispatcher::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 
2579 (qcocoaeventdispatcher.mm:430)
61  org.qt-project.QtCore               0x0000000102255a7f 
QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 431 (atomic:929)
62  org.qt-project.QtCore               0x000000010225a002 
QCoreApplication::exec() + 130 (qcoreapplication.cpp:1383)
63  com.sticksoftware.QtSLiM            0x00000001003ba56e main + 670
64  libdyld.dylib                       0x00007fff6d4a17fd start + 1


_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to