aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/jsruntime/qv4variantobject.cpp2
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp12
2 files changed, 14 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4variantobject.cpp b/src/qml/jsruntime/qv4variantobject.cpp
index 3e659eec5a..d08d2a0812 100644
--- a/src/qml/jsruntime/qv4variantobject.cpp
+++ b/src/qml/jsruntime/qv4variantobject.cpp
@@ -174,6 +174,8 @@ QV4::ReturnedValue VariantPrototype::method_valueOf(CallContext *ctx)
case QVariant::Bool:
return Encode(v.toBool());
default:
+ if (QMetaType::typeFlags(v.userType()) & QMetaType::IsEnumeration)
+ return Encode(v.toInt());
break;
}
}
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index 4e9da046b5..da57d7786a 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -70,6 +70,7 @@ private slots:
void newArray_HooliganTask233836();
void newVariant();
void newVariant_valueOfToString();
+ void newVariant_valueOfEnum();
void newRegExp();
void jsRegExp();
void newDate();
@@ -439,6 +440,17 @@ void tst_QJSEngine::newVariant_valueOfToString()
}
}
+void tst_QJSEngine::newVariant_valueOfEnum()
+{
+ QJSEngine eng;
+ {
+ QJSValue object = eng.toScriptValue(QVariant::fromValue(Qt::ControlModifier));
+ QJSValue value = object.property("valueOf").callWithInstance(object);
+ QVERIFY(value.isNumber());
+ QCOMPARE(value.toInt(), static_cast<qint32>(Qt::ControlModifier));
+ }
+}
+
void tst_QJSEngine::newRegExp()
{
QJSEngine eng;