diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2022-09-21 15:43:40 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-09-29 20:02:39 +0000 |
commit | 1a3b92286909942d0aab29439ad9702b20e20344 (patch) | |
tree | e5fba7d6497c5d50631b69b33d77f51aff0c0c7b | |
parent | 385d2ecb0434aead802a0cd5ab4ecdba2f407dfe (diff) |
createTemporaryObject: account for undefined parent argument
c837be7beab1c217b8f163b9a2d53ca12fd2c95e results in a warning for code
that does this:
let parent = createTemporaryObject(window)
The warning was:
"QML Component: Unsuitable arguments passed to createObject(). The first
argument should be a QObject* or null, and the second argument should
be a JavaScript object or a QVariantMap"
Avoid the warning by setting parent to null if it's undefined.
Update the relevant self-tests to fail on warnings so that it's
tested.
Change-Id: I04e9423e7c08d370d8055a8b8e766827a9709919
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit e7f23ef9b09b5fc522598abec20e541490ceba3d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qmltest/TestCase.qml | 3 | ||||
-rw-r--r-- | tests/auto/qmltest/selftests/tst_createTemporaryObject.qml | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/qmltest/TestCase.qml b/src/qmltest/TestCase.qml index 7055bcd974..a69c2fe6f6 100644 --- a/src/qmltest/TestCase.qml +++ b/src/qmltest/TestCase.qml @@ -631,6 +631,9 @@ Item { throw new Error("QtQuickTest::fail"); } + if (parent === undefined) + parent = null + var object = component.createObject(parent, properties ? properties : ({})); qtest_temporaryObjects.push(object); return object; diff --git a/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml b/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml index ec3387a38b..a54e5f1e7b 100644 --- a/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml +++ b/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml @@ -25,6 +25,8 @@ TestCase { } function init() { + failOnWarning(/.?/) + // The items are destroyed after cleanup(), so we check here after every test, // and once for the last test in cleanupTestCase(). verifyNoChildren(); @@ -125,7 +127,8 @@ TestCase { { tag: "omit", expectedParent: null }, { tag: "undefined", parent: undefined, expectedParent: null }, { tag: "null", parent: null, expectedParent: null }, - { tag: "1", parent: 1, expectedParent: null }, + { tag: "1", parent: 1, expectedParent: null, + ignoreWarning: /.*Unsuitable arguments passed to createObject.*/ }, { tag: "testCase", parent: testCase, expectedParent: testCase } ]; } @@ -133,6 +136,10 @@ TestCase { // Tests that an invalid or missing parent argument results in a parentless object. // This is the same behavior as displayed by component.createObject(). function test_fromComponentParent(data) { + // ignoreWarning takes precedence over failOnWarning (which we call in init()). + if (data.hasOwnProperty("ignoreWarning")) + ignoreWarning(data.ignoreWarning) + var object = data.hasOwnProperty("parent") ? createTemporaryObject(itemComponent, data.parent) : createTemporaryObject(itemComponent); |