Qt拖放到Windows资源管理器:我如何知道放置的目标路径

2022-01-11 00:00:00 qt drag-and-drop c++

我要做的是显示在线文件的列表视图,就像 FTP 客户端列出 FTP 服务器上的所有文件一样,可以将任意一行或多行拖动到任何本地文件夹以保存拖动的文件在那里.

What I'm trying to do is to display a listview of online files, just like an FTP client lists all the files on the FTP server, and one can drag any row or rows to any local folder to save the dragged files right there.

我计划通过以下步骤来实现:

I'm planning to implement this through the follwing steps:

  1. 初始化拖拽事件,并将选中文件的路径保存到服务器[完成]
  2. 子类 QMimeData 类,并覆盖retrieveData 函数,就像这个线程建议的那样这里 [完成]
  3. 只需完成拖放过程,然后找到拖放的目标路径,例如 C:somefoldersubfolder,然后将所有文件下载到那里,就完成了.【未完成】
  1. init the drag event, and save the selected files' path on the server [done]
  2. subclass QMimeData class, and overwrite retrieveData function just as this thread suggests here [done]
  3. Just finish the drag and drop process, and find the dropped destination path, say C:somefoldersubfolder, then download all the files there, job done. 【not done】

但我无法找到任何地方来获取放置的目标路径,甚至无法通过处理 dragEnterdragMovedragLeavedrop 事件.我也进行了大量的谷歌搜索,发现了一些类似的问题,但从来没有任何可靠的答案.

But I could not find anywhere to get the dropped destionation path, not even by processing dragEnterdragMovedragLeavedrop events. I've also done tons of google search, found some similar questions but never any solid answer.

请对此有所了解.这种解决方案甚至可以与 QT 一起使用吗?我应该如何获得目标路径或者有没有其他方法可以实现这个目标?

Please shed some light on this. Is this solutuion even doable with QT ? How should I get the destination path or is there any other way to achieve this goal ?

推荐答案

对于任何正在寻找这个的人,我可能会找到答案,但这并不容易,并且可能取决于平台.

For anyone who's searching for this, I might find an answer, but it ain't easy and could be platform dependent.

经过大量(字面意思)搜索,我在 FileZilla's 源代码中找到了解决方案,结果证明可以应付在这种情况下,您需要:

After tons of (literally) search, I found a solution in FileZilla's source code, turns out to cope with such situatuation, you need:

  1. 您需要一个 shell 扩展来监控(或其他)拖动过程
  2. 开始正常的拖放操作
  3. 当鼠标落下时,什么都不做,让整个拖放过程结束
  4. 通过 shell 扩展,您可以获得实际的目标路径,然后将文件下载到那里.

技术细节请访问FileZilla官网

我认为这仅适用于Windows,如果有人得到其他平台的答案,请告诉我!

I think this is for windows only, if anyone get the answer for other platforms, please let me know!

相关文章