Drag the file from the application to Explorer. Can my application copy?

In Qml, I can start drag and drop using the mime type text/uri-list to trigger the copy action from my application to the file explorer, for example

  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 great when using file: and http: URI.

However, my real data is not available as a URI, but is stored in a database. I can’t quickly save the temperature, because it can take a few seconds, and the user does not want a delay when dragging it.

How can I get the target URI after the fall and do the copying myself? Or can only the target be copied?

In the latter case, do I need to make my data accessible through an internal HTTP server? How do I even know which URI scheme is supported by file browsers on Linux, Windows, and OS X?

+5
source share
1 answer

I would use something like:

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

and then I will make the requested data available on the HTTP server in the application (which can then easily retrieve the object with the identifier equal to 12345 in my example from the database) ... (after the copy operation I don’t think it's embarrassing if your the user waits a few seconds while the system retrieves the object from the database).

0
source

Source: https://habr.com/ru/post/1233877/


All Articles