Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.4.0 RC
-
OS X 10.9.5
-
I2377523a9286519402ab9127ed7f3fa66e39a679
Description
Description
Reading the data of a QMimeData object and writing it back corrupts Urls which are stored inside this data:
mimeData->setData("text/uri-list", mimeData->data("text/uri-list"));
"Corrupt" means that other applications (which do not use Qt) such as Finder will not be able to read the Urls.
Reproduction
Try to execute a drag event which contains mime data with Urls and drop it on a Finder window.
If you execute 'mimeData->setData("text/uri-list", mimeData->data("text/uri-list"));' using the QMimeData of the event then Finder will deny the drop.
This does not only apply to Finder but also to other applications (which do not use Qt but e.g. Cocoa).
Example code
QMimeData *mimeData = new QMimeData; // Create Urls QList<QUrl> urls; urls.append(QUrl::fromLocalFile("/Path/To/File.png")); mimeData->setUrls(urls); // This corrupts the Urls: foreach (const QString format, mimeData->formats()) mimeData->setData(format, mimeData->data(format)); // This would fix the Urls again: // mimeData->setUrls(mimeData->urls()); // Execute the drag and drop: QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); // ... drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
Note
The Qt “drop site“ example will read the corrupted Urls correctly (if you check mimeData->hasUrls() before mimeData->hasText() in DropArea::dropEvent()). However, the OS and any other cocoa application are not able to read the Urls.
This is a tiny example which tries to read the Urls:
@interface DragDropImageView : NSImageView <NSDraggingSource, NSDraggingDestination, NSPasteboardItemDataProvider>
{}
@implementation DragDropImageView - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender { NSPasteboard * paste = [sender draggingPasteboard]; NSURL* fileURL; fileURL = [NSURL URLFromPasteboard: paste]; if (fileURL != NULL) { [[self window] setTitle: [fileURL absoluteString]]; } return NSDragOperationNone; }
If you execute 'mimeData->setData("text/uri-list", mimeData->data("text/uri-list"));' in your Qt application like shown above then "fileURL" will be NULL and URLFromPasteboar logs:
CocoaDragAndDrop[42373:303] Couldn't get a copy of a URL-flavored data from the pasteboard.
CocoaDragAndDrop[42373:303] Looked for URLs on the pasteboard, but found none.
Operating System
This seems to affect only OS X and could not be reproduced on Windows 8.1.