Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-74232

Custom formats are ignored while Dragging and Dropping files on Windows



    • Platform/s:
    • Commits:
      c096d97097e37b36281f8ad25852a2397f20a32f (qt/qtbase/5.12)


      To properly drag and drop files in Windows,  the IDataObject should at least contain the following formats:

      • A list of files using the CF_HDROP format (0x15).  This is properly translated by Qt using the MIME text/uri-list format.
      • A Shell IDList Array format (0xC0F6), a list of PIDLs.  This is a must and the developers should implement it themselves.  This always needs to be present.
      • A FileName format (0xC006), nowadays ignored but it should be there just to be consistent.
      • A FileNameW format (0xC007) also mostly ignored by the applications but it should be there.

      Most applications like File Manager even the Windows Explorer include many more formats when drag & dropping files but those are like the minimum.

      The problem is that when you have a QMimeData with a text/uri-list format, all the other formats you set using setData() are totally ignored when you drag from your Qt application and drop it in another application.

      The reason is because in qtbase/src/plugins/platforms/windows/qwindowsdropdataobject.cpp in the QWindowsDropDataObject methods to get the data there's a call to a "shouldIgnore()" function with the following remark:

      // If the data is text/uri-list for local files, tell we can only export it as CF_HDROP.

      I mean, what?  If the DataDrop object has a text/uri-list then everything else is totally ignored.

      This causes that the drag & drop files from your Qt Application in Windows to a different application only works if that application is fairly recent.  A little older applications only look for the "Shell IDList Array" and ignore the file list.  Then I can't drop my files to those applications because all formats are totally ignored.

      That shouldIgnore() function simply shouldn't exist.  Let the developers add as many formats as they want.

      Also this worked back in Qt 5.9 where the QWindowsDropDataObject (which extends QWindowsOleDataObject) didn't exist.  The QWindows::drag() function used a QWindowsOleDataObject that wasn't ignoring anything and everything worked properly.

      The QWindowsDropDataObject was explicitly created to ignore all other formats when a text/uri-list is present.  If you read the source code you'd read:

      Only allows "text/uri-list" data to be exported as CF_HDROP, to allow dropped
      files to be attached to Office applications (instead of adding an URL link).

      Well this shouldn't ignore other formats!! Even if only the text/uri-list format should be exported as CF_HDROP you just can't get rid of the rest!



          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.



              anrocha André De La Rocha
              scorpius Naikel Aparicio
              0 Vote for this issue
              4 Start watching this issue



                  Gerrit Reviews

                  There are no open Gerrit changes