In my program I've reimplemented the dropEvent and the mousePressEvents in order to let me re-parent QDockWidgets by dragging and dropping them between different instances of an inherited QMainWindow class. I previously had an issue where after reparenting a QDockWidget I had to mouseover the name of the QDockWidget in the top corner of the window in order for me to be able to select where to dock the widget in its new window rather than this happening immediately upon the drop completion. I've since fixed that by adding these two lines to the dropEvent():
QEvent reParentEvent
(QEvent::MouseMove);
// Mouse move (QMouseEvent) - 5
QEvent reParentEvent(QEvent::MouseMove); // Mouse move (QMouseEvent) - 5
QApplication::sendEvent(child, &reParentEvent);
To copy to clipboard, switch view to plain text mode
However somehow this introduced a new bug where sometimes during the drop (it seems to occur especially often when you reparent the dockwidget from the window that you spawn second into the window that was spawned first) a segfault occurs. Note I've never seen this crash without the above 2 lines of code, but I have no idea why these lines would cause a crash. Alternatively if there was another way to fix my issue of docking widgets immediately upon drop without causing intermittent crashes or the need to mouseover the QDockWidget's title that would also work.
I've created and attached a small qtproject (Here: ForQtForums.tar.gz) to demonstrate the issue. Note if you comment/remove lines 82 and 83 from src/TableViewWindow.cpp the crash no longer occurs, but then you'll get the delayed docking action issue instead. I've found the most repeatable way to reproduce the crash is to create two windows containing QDockWidgets (press ctrl+N while on the mainwindow or use the dropdown menu), and then drag and drop the QDockWidget from the second window that was created into the first window that was created. If it doesn't crash at this point just restart the application and try again as it's faster than reparenting at random until it crashes after this point (It will eventually but sometimes it's after 2 more drag and drops, and sometimes after 15).
Also for some reason my drag and drop to reparent only works with both right and left click held down, and not just left click like I wanted so if someone could also tell me how to fix that in the meantime it'd be appreciated.
Thanks
Bookmarks