aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFushan Wen <qydwhotmail@gmail.com>2022-11-01 22:35:24 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-11-04 00:47:03 +0000
commit22de23c4bb9ac5e2c545e9de3149a7d4f8edd5ee (patch)
tree48034525c2e14f99a243940013ad6e1a0c545f81 /src
parentbfdccf29e7d5e748e47ccb0fe5ae3ed8499a1a89 (diff)
Don't convert QByteArray in `startDrag`
QMimeData::setData expects the provided data to contain the correctly encoded QByteArray, so if the variant contains a QByteArray, then take it as is to avoid data loss. If the variant is not already a byte array, then we ideally would make sure that the mime type (i.e. the key of the map) and the QVariant's type are compatible (image/png with a QImage works; text/plain with a QImage does not). This changes behavior and needs to be a follow-up commit. Fixes: QTBUG-71922 Change-Id: I9b9f10fd332e1f9568f6835a69a1c359457f823c Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 062f9bf57657b54dc708015ec5fed3c89e5cc3ca) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquickdrag.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp
index 4d54a28d8a..6c1f56de63 100644
--- a/src/quick/items/qquickdrag.cpp
+++ b/src/quick/items/qquickdrag.cpp
@@ -446,7 +446,9 @@ void QQuickDragAttached::setKeys(const QStringList &keys)
\qmlattachedproperty stringlist QtQuick::Drag::mimeData
\since 5.2
- This property holds a map of mimeData that is used during startDrag.
+ This property holds a map from mime type to data that is used during startDrag.
+ The mime data needs to be a \c string, or an \c ArrayBuffer with the data encoded
+ according to the mime type.
*/
QVariantMap QQuickDragAttached::mimeData() const
@@ -731,8 +733,12 @@ Qt::DropAction QQuickDragAttachedPrivate::startDrag(Qt::DropActions supportedAct
QDrag *drag = new QDrag(source ? source : q);
QMimeData *mimeData = new QMimeData();
- for (auto it = externalMimeData.cbegin(), end = externalMimeData.cend(); it != end; ++it)
- mimeData->setData(it.key(), it.value().toString().toUtf8());
+ for (auto it = externalMimeData.cbegin(), end = externalMimeData.cend(); it != end; ++it) {
+ if (it.value().typeId() == QMetaType::QByteArray)
+ mimeData->setData(it.key(), it.value().toByteArray());
+ else
+ mimeData->setData(it.key(), it.value().toString().toUtf8());
+ }
drag->setMimeData(mimeData);
if (pixmapLoader.isReady()) {