Drag file from application to explorer. Can my application do the copying?

廉价感情. 提交于 2021-02-07 07:23:14

问题


In Qml I can start a drag using the text/uri-list mime type in order to start a copy action from my application into a file explorer, e.g.

        Item {
            id: draggable
            anchors.fill: parent
            Drag.active: mouseArea.drag.active
            Drag.hotSpot.x: 0
            Drag.hotSpot.y: 0
            Drag.mimeData: { "text/uri-list": "file:///home/myname/Desktop/avatar.jpeg" }
            Drag.supportedActions: Qt.CopyAction
            Drag.dragType: Drag.Automatic
            Drag.onDragStarted: { }
            Drag.onDragFinished: {
                console.log("Time to copy")
            }
        } // Item

or

        Item {
            id: draggable
            anchors.fill: parent
            Drag.active: mouseArea.drag.active
            Drag.hotSpot.x: 0
            Drag.hotSpot.y: 0
            Drag.mimeData: { "text/uri-list": "https://farm1.staticflickr.com/713/21777111068_e3310cfb94_k.jpg" }
            Drag.supportedActions: Qt.CopyAction
            Drag.dragType: Drag.Automatic
            Drag.onDragStarted: { }
            Drag.onDragFinished: {
                console.log("Time to copy")
            }
        } // Item

(see also Qt Quick Examples - externaldraganddrop)

This works fine given file: and http: URIs.

However my real data is not available as an URI but stored in a database. I cannot quickly store to temp because that can take seconds and user does not want a delay in the moment he starts a drag.

Is it somehow possible to get the target URI after the drop and do the copying myself? Or can only the target do the copying?

In the later case, do I need to make my data available via an internal HTTP-Server? How do I even know which URI scheme is supported by the file browsers on Linux, Windows and OS X?


回答1:


I would use something like:

Drag.mimeData: { "text/uri-list": "http://localhost:8080/datarepository?id=12345" }

and then I'll make available the requested data on an in-application HTTP server (that then can easily extract the object having ID equal to 12345 in my example from DB)... (once the copy operation has started I don't think that it is a shame if your user waits some seconds while the system extracts the object from the DB).



来源:https://stackoverflow.com/questions/33174044/drag-file-from-application-to-explorer-can-my-application-do-the-copying

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!