How to get the drop target when the drop occurs outside the application?


QDrag::target returns a pointer to QObject. Within a Qt widgets application this makes sense, because all possible drop targets are some kind of QWidgets, i.e. QObjects. When the drop action is outside the app, it does not make sense to return anything than a null pointer, because:

  1. If not, a pointer to which QObject should target return instead?

  2. If you somehow manage to get some kind of a pointer, to which type would you cast it to access the information you need, because QObject definitely does not contain any file URLs?

I admit the documentation of QDrag::target is not as explicit on this, as the documentation of QDropEvent::source:

Returns the target of the drag and drop operation. This is the widget where the drag object was dropped.

compared to

If the source of the drag operation is a widget in this application, this function returns that source; otherwise it returns nullptr.

However, the This is the widget part gives a hint about this fact, that the target should be a widget.


Instead of a drag functionality use QFileDialog::getSaveFileUrl to get the url of the file.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top