[Interest] nested mouse events after deleting a QObject on OS X

René J.V. Bertin rjvbertin at gmail.com
Tue Feb 10 19:06:27 CET 2015


This is a bit of a call for attention to an issue with Qt 4.8.6 I reported here:
https://bugreports.qt.io/browse/QTBUG-44343

In short, the qt_mac_handleMouseEvent() function which does what its name says, has the following lines in it:

    if (eventType == QEvent::MouseButtonRelease) {
        // A mouse button was released, which means that the implicit grab was
        // released. We therefore need to re-check if should send (delayed) enter leave events:
        // qt_button_down has now become NULL since the call at the top of the function. Also, since
        // the relase might have closed a window, we dont give the nativeWidget hint
        qt_mac_getTargetForMouseEvent(0, QEvent::None, localPoint, globalPoint, nativeWidget, &widgetUnderMouse);

Despite "we dont give the nativeWidget hint", qt_mac_getTargetForMouseEvent() is called with nativeWidget instead of NULL, which in turn can lead to a crash when nativeWidget is stale (remnants of a deleted object), accessing nativeWidget->isVisible() .
When called with NULL, that function will look up the application's widget that corresponds to the event location or else the current mouse co-ordinates.

I *think* that might cause the application to handle events that were not intended for it, which could explain why one of my applications now no longer crashes because it accesses a stale pointer, but has started to show a kind of own life by doing things (just opening documents for now :)) that I never asked for.

To be sure: I take it there is no reliable way to determine if a QWidget* is a stale pointer, or is there?

Preventing this might be as simple as not calling qt_mac_getTargetForMouseEvent() when the application is not the front application, which should always be the case in normal operation? What's the best way to check if we're the current foreground or key application?

One cannot be sure that calling nativeWidget->isVisible() when nativeWidget is stale always leads to a SIGSEV or similar exception, correct?

Thanks,
R.



More information about the Interest mailing list