I’ve written a little file-transfer application written in C++ using Qt 4.x … it logs into a server, shows the user a list of files available on the server, and lets the user upload or download files.
This all works fine; you can even drag a file in from the desktop (or from an open folder), and when you drop the file icon into the server-files-list-view, the dropped file gets uploaded to the server.
Now I have a request for the opposite action as well… my users would like to be able to drag a file out of the server-files-list-view and onto the desktop, or into an open folder window, and have that file get downloaded into that location.
That seems like a reasonable request, but I don’t know how to implement it. Is there a way for a Qt application to find out the directory corresponding to where “drop event” occurred, when the icon was dropped onto the desktop or into an open folder window? Ideally this would be a Qt-based platform-neutral mechanism, but if that doesn’t exist, then platform-specific mechanisms for MacOS/X and Windows (XP or higher) would suffice.
Any ideas?
Look at
QMimeDataand its documentation, it has a virtual functionthis means to do you drag to the outside you implement this functions accordingly
The delayed encoding examples shows this principle.
You will probably also have to override
hasFormatandformatsto provide the appropriate types,application/octet-streamprobably being the one that might get you the most play, you will probably have to read up on how windows specifically handles drag and drop using mime types.I don’t know how you will supply the file name under which the file is saved, but you will probably have to get into the windows side of things. Looking at the source of
QWindowsMimemight also help. There might me a multiple step process where you will get requests fortext/uri-listdata for the filenames and thenapplication/octet-streamfor the data.Hope this helps