diff options
author | Andy Shaw <andy.shaw@qt.io> | 2020-07-03 08:23:32 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2020-07-03 14:30:45 +0200 |
commit | a056cb9595ea4a41c93f4c912719f9523b943d3b (patch) | |
tree | dfdd371f5a59cb5e93cdaab040689d55ff0d406a /src/qml/jsruntime | |
parent | 256503fadf5a925933fc03980d7c878643b1fdca (diff) |
Give a better score for methods with a convertable type when matching
When it is looking for a matching method based on the argument types,
then if a QVariant can be converted to that type then it should give a
better score for that method. This is so that it can see it as being
more viable a choice when calling the method instead of potentially
not being able to find a matching one.
Pick-to: 5.15
Change-Id: Ief7e11feacd1d0b0959330af2576c2d01affbc54
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 4d422a3620..d37f80ab0a 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1468,8 +1468,11 @@ static int MatchScore(const QV4::Value &actual, int conversionType) } if (obj->as<QV4::QQmlValueTypeWrapper>()) { - if (obj->engine()->toVariant(actual, -1).userType() == conversionType) + const QVariant v = obj->engine()->toVariant(actual, -1); + if (v.userType() == conversionType) return 0; + else if (v.canConvert(conversionType)) + return 5; return 10; } else if (conversionType == QMetaType::QJsonObject) { return 5; |