[OS X] Prevent a crash in the IdealDockWidget's context menu
Review Request #128016 - Created May 25, 2016 and discarded
|René J.V. Bertin|
OS X can be capricious when instances corresponding to a widget are deleted, if the class in question uses "native" ObjC SDKs behind the scenes. Pending events can in that case be (generated and) delivered to objects that were already deleted.
According to the documentation, one should prefer to use
QObject::deleteLater()rather than the regular, direct
deletewhether it be explicit or implicit.
I've long used a local patch that uses this approach in order to prevent a recurring crash after using the context menu of the "ideal dock widget". Somehow I never put it up for review here, apparently.
Builds and permits reliable behaviour on both OS X and Linux.
René, can you tell why exactly this QMenu instance needs this delayed deletion? There are other QMenus created on the stack elsewhere in KDevelop code, even Qt code has QMenus on the stack (e.g. static QMenu::exec(QList<QAction> actions, const QPoint &pos, QAction at, QWidget *parent) implementation), so being deleted in sync (and others for some reason are on the heap, yet still deleted in-sync).
So why it this needed here, but not elsewhere? That information is missing here, and thus this code will be some "magic" fix to an unknown specific problem, which as a results decreases code maintainability. There should be at least a comment in the code, why this extra treatment is done here.