Copying file(s) with drag and drop from Qt 5.2 application to file system

1.4k Views Asked by At

How do I go about generating a file drag and drop operation in a Qt 5.2 application that performs a copy (or move) in the file system (Windows, Mac, etc.)? More specifically: Generate a drag with 1+ file paths that will perform a copy/move on those files when dropped onto the system.

Is there a standard mime-type I can use for this - providing file paths as mime data?

1

There are 1 best solutions below

3
On

QMimeData has a functionality to add a text/uri-list.

To drag/drop a file onto the system add a QUrl that starts with file:/// followed by your path.

QList<QUrl> urls;

list.append(QUrl("file:///path");

QMimeData* mimeData = new QMimeData;

mimeData->setUrls(list);