summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorJohan Klokkhammer Helsing <johan.helsing@qt.io>2018-12-13 11:25:24 +0100
committerJohan Helsing <johan.helsing@qt.io>2019-01-23 20:56:35 +0000
commit589a01ff6b1eacf81e74a5fc4801572135214f43 (patch)
tree76056df074d76299b698f1b17c2ea2a0f8a44457 /src/corelib/kernel
parent461ef575bcf778ba24b0be6b775098d4b80ae5e1 (diff)
QMimeData: Prefer UTF-8 when multiple charsets are available
This was especially a problem on Wayland where both "text/plain" (us-ascii) and "text/plain;charset=utf-8" are typically available. I.e. we would prefer ascii over utf-8, losing special characters. Fixes: QTBUG-54786 Change-Id: I985f66e16fcd5125e800c86c4d3949d210e939ba Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qmimedata.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/corelib/kernel/qmimedata.cpp b/src/corelib/kernel/qmimedata.cpp
index c8ad1bc43f..9a98db21d3 100644
--- a/src/corelib/kernel/qmimedata.cpp
+++ b/src/corelib/kernel/qmimedata.cpp
@@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE
static inline QString textUriListLiteral() { return QStringLiteral("text/uri-list"); }
static inline QString textHtmlLiteral() { return QStringLiteral("text/html"); }
static inline QString textPlainLiteral() { return QStringLiteral("text/plain"); }
+static inline QString textPlainUtf8Literal() { return QStringLiteral("text/plain;charset=utf-8"); }
static inline QString applicationXColorLiteral() { return QStringLiteral("application/x-color"); }
static inline QString applicationXQtImageLiteral() { return QStringLiteral("application/x-qt-image"); }
@@ -399,6 +400,10 @@ bool QMimeData::hasUrls() const
QString QMimeData::text() const
{
Q_D(const QMimeData);
+ QVariant utf8Text = d->retrieveTypedData(textPlainUtf8Literal(), QVariant::String);
+ if (!utf8Text.isNull())
+ return utf8Text.toString();
+
QVariant data = d->retrieveTypedData(textPlainLiteral(), QVariant::String);
return data.toString();
}