Crash within Qt Code using drag and drop (Qt BUG?)
-
Since I have only been debugging with the Qt source today, I have seen it happens in more than one location in the function above.
It seems to me to be the data pointer becomes invalid, if I could find out what this is then I would be able to trace it back, however, it is obtained from
QThreadData * volatile * pdata = &receiver->d_func()->threadData;
and d_func() doesn't seem accessible from the source I have.
@
} QThreadData * volatile * pdata = &receiver->d_func()->threadData; QThreadData *data = *pdata; if (!data) { // posting during destruction? just delete the event to prevent a leak delete event; return; } // lock the post event mutex data->postEventList.mutex.lock(); // if object has moved to another thread, follow it while (data != *pdata) { data->postEventList.mutex.unlock(); <============= CRASH CAN ALSO HAPPEN HERE data = *pdata; if (!data) { // posting during destruction? just delete the event to prevent a leak delete event; return;
@
-
First thing that comes to my mind:
Do you use the delete operator or deleteLater function from QObject ? -
Sorry but, yes to what ?
-
I would rather avoid using delete on widgets, unless you're really sure about the state of that widget (parenting etc...)
And since the drag object is a child of your current widget, it should also be automatically deleted.
And last thing, i would set _widget to 0 in the destructor of your custom QMimeData (or use something like a QPointer)
-
I need to delete the widget, if it is not dropped as it is created for being dragged into the container, if the drag fails it should be deleted, otherwise it will sit in memory until the application is closed.
The code that calls the deletion of the drag does not get called, it is only for if the creation of the widget fails, which does not happen.
I will set the widget to 0 in the destruction of the mime data, and see if this helps.
-
Why do you create it there then ? Wouldn't it be safer to serialize your widget properties (i.e. in xml) and then use that to create the widget in the drop function ? So if no drop occurs, no need to handle that widget.
-
Widgets can also be moved, from one place to another. These widgets are connected up to the backend via a (thread safe) shared control object and all setting show on the GUI match up. Due to this, it is far easier to create the widget and then destroy it if required.
I really don't think the issue is with deleting the widgets. As looking into the code, the object getting deleted is the QXdndDropTransaction object. This is handled by Qt itself.