tuli
19th July 2018, 13:55
I implemented some custom drag+drop in the standard way. Part of the dragging code:
QDrag* drag = new QDrag(this);
drag->exec();
...
Now I am wondering: Who owns the QDrag* object 'drag'?
It seems to me that I do, and I have to do delete the drag object before returning:
QDrag* drag = new QDrag(this);
drag->exec();
...
delete drag;
...
However, in none of the Qt drag+drop examples this is done. They just let the pointer go out of scope and dont bother about it!
(note that the 'this' passed to the constructor is not a 'QObject* parent' but the source of the dragging.)
https://doc.qt.io/qt-5/qtwidgets-draganddrop-fridgemagnets-dragwidget-cpp.html
The documentation doesnt say anything special either.
Who owns it? Do I have to delete it or not?
QDrag* drag = new QDrag(this);
drag->exec();
...
Now I am wondering: Who owns the QDrag* object 'drag'?
It seems to me that I do, and I have to do delete the drag object before returning:
QDrag* drag = new QDrag(this);
drag->exec();
...
delete drag;
...
However, in none of the Qt drag+drop examples this is done. They just let the pointer go out of scope and dont bother about it!
(note that the 'this' passed to the constructor is not a 'QObject* parent' but the source of the dragging.)
https://doc.qt.io/qt-5/qtwidgets-draganddrop-fridgemagnets-dragwidget-cpp.html
The documentation doesnt say anything special either.
Who owns it? Do I have to delete it or not?