aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlproperty.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/qml/qqmlproperty.cpp')
-rw-r--r--src/qml/qml/qqmlproperty.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index d45f3ac19b..931adb9a13 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -1387,8 +1387,30 @@ bool QQmlPropertyPrivate::write(QObject *object,
bool ok = false;
QVariant v;
- if (variantType == QVariant::String)
- v = QQmlStringConverters::variantFromString(value.toString(), propertyType, &ok);
+ if (variantType == QVariant::String) {
+ const QString &str = value.toString();
+ const bool targetIsChar = (propertyType == qMetaTypeId<QChar>()
+ || propertyType == qMetaTypeId<char>()
+ || propertyType == qMetaTypeId<unsigned char>());
+ // If the string contains only one character and the target is a char, try converting it.
+ if (targetIsChar) {
+ if (str.size() != 1)
+ return false; // We can only convert if the string contains exactly one character.
+
+ const QChar &qChar = str.at(0);
+ if (propertyType == qMetaTypeId<QChar>()) {
+ v = qChar;
+ ok = true;
+ } else if (propertyType == qMetaTypeId<char>() || propertyType == qMetaTypeId<unsigned char>()) {
+ const char c = qChar.toLatin1();
+ v = c;
+ ok = (qChar == c);
+ }
+ } else {
+ v = QQmlStringConverters::variantFromString(str, propertyType, &ok);
+ }
+ }
+
if (!ok) {
v = value;
if (v.convert(propertyType)) {