[Qt-interest] Drag and Drop when source is deleted
Bo Thorsen
bo at fioniasoftware.dk
Fri May 20 11:42:12 CEST 2011
Den 20-05-2011 11:04, Martin Grossberger skrev:
>> Den 19-05-2011 17:54, Martin Grossberger skrev:
>>> Hello all,
>>>
>>> I have an issue with Drag&Drop, with which I hope you can help me:
>>> I have subclassed (twice) a QWidget and enabled dragging it. The widget
>>> also gets automatically deleted when an event hits.
>>> Now, if the widget gets deleted while I am dragging it, I can continue
>>> dragging, however once I drop it somewhere, the program crashes. The
>>> stacktrace from the debugger is:
>>> 0 QDrag::setMimeData qdrag.cpp 145 0x047eb579
>>> 1 QDragManager::drag qdnd_win.cpp 973 0x0484fa75
>>> 2 QDrag::start qdrag.cpp 314 0x047eb8b6
>>> 3 MyCustomWidget::dragEvent mycustomwidget.cpp 1285 0x0041ca80
>>> 4 MyWidget::mouseMoveEvent mywidget.cpp 573 0x00526286
>>> 5 MyCustomWidget::mouseMoveEvent mycustomwidget.cpp 1486
>>> 0x0041e814
>>> 6 QWidget::event qwidget.cpp 7983 0x0482cee8
>>> 7 QApplicationPrivate::notify_helper qapplication.cpp 4300
>>> 0x047e2520
>>> 8 QApplication::notify qapplication.cpp 3865 0x047e0723
>>> 9 QCoreApplication::notifyInternal qcoreapplication.cpp 704
>>> 0x6a1fd302
>>> 10 QCoreApplication::sendSpontaneousEvent qcoreapplication.h
>>> 218 0x04e36eba
>>> 11 QApplicationPrivate::sendMouseEvent qapplication.cpp 2963
>>> 0x047def40
>>> 12 QETWidget::translateMouseEvent qapplication_win.cpp 3230
>>> 0x04847f10
>>> 13 QtWndProc at 16 qapplication_win.cpp 1623 0x0484309d
>>> 14 USER32!IsDialogMessageW C:\Windows\syswow64\user32.dll 0
>>> 0x75fa6238
>>> 15 ?? 0 0x00141dec
>>> 16 ?? 0 0x00000200
>>> 17 USER32!AllowForegroundActivation
>>> C:\Windows\syswow64\user32.dll 0 0x75fa68ea
>>> 18 qt_is_translatable_mouse_event qapplication_win.cpp 1395
>>> 0x04842675
>>> 19 USER32!GetMessageExtraInfo C:\Windows\syswow64\user32.dll
>>> 0 0x75fa7d31
>>> 20 ?? 0 0x00000000
>>> ...<Mehr>
>>>
>>> Is there something I can do to prevent the crash (other than deleting
>>> the widget)? Did I miss something?
>>
>> It sounds like you are trying to drag the widget? If that's the case,
>> you have to rewrite this. You have to drag only data, not active objects.
>>
>> Bo Thorsen,
>> Fionia Software.
>>
> Thanks for your input, I have read about that a while ago and rewrote
> the code so that the QMimeData Object only saves an ID of the widget,
> not a pointer to the actual widget.
> However, the program still crashes before I can even check if the widget
> still exists on dropping.
You should go further than that and put the data from the widget in the
drag object.
widget::startDrag() {
// start drag code here
deleteLater();
// boom
}
Do not expect the widget to be alive when the drop happens.
Also, you should be a good citizen if possible and implement text or
image or whatever, so you can drag to other applications as well.
Bo Thorsen,
Fionia Software.
--
Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk
More information about the Qt-interest-old
mailing list