I have a Qt desktop application that works on Linux and Windows. At some point I’m hoping to port it to MacOS X and other *nix systems too.
My problem is that, a part of the application has a functionality that allows users to drag and drop files into, and out from an archive. The UI is kinda like that of WinZip or similar GUI based archivers. But Qt’s drag and drop system wants the data to be prepared when the user starts dragging files from the archive.
What I currently do is, extract the dragged files to a temporary location, and supply those file names as data. But it’s undesirable because extracting deep directory trees take a good amount of time, and it causes the GUI to freeze during that time. It would be nice if I could do that operation when the user decides to drop the files, not when he/she starts to drag. Unfortunately Qt docs don’t say anything about this.
I know how to achieve this using Windows API, and I’m pretty sure that most systems have a way to do that too. But I want to avoid writing platform specific code as much as possible.
Is there a Qt way to achieve that? Am I missing something?
I may be misunderstanding, but I think what you want to do is supply enough information in a QMimeData for the QDrag you create that you can find the files in the archive after the user drops it without having to extract them first. So, if your code on the drop end doesn’t know which archive the files have come from, you need to supply the path to the archive in your mime data, too.
The drag starts as a message:
“I’m dragging Archive1:FileA, Archive1:FileB” but no file extraction.
It ends on the other end by interpreting the message and then extracting the files. I’d probably set up some kind of simple ICD for both sides of the message transfer. If you can only drag from one archive at a time, maybe a string list with the first element being the archive and following ones being the files:
I hope this helps!