diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2024-03-19 15:55:12 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-03-21 10:41:29 +0100 |
| commit | eb79815fbfad7d4e7fb4be856dc0dd43be76fdb9 (patch) | |
| tree | 6015c799ae4ddbc2f362322cb0c1bb5f5705d4b2 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
| parent | f48ada60c3d6b56881b7355a305ec3e9c00884a5 (diff) | |
QmlCompiler: Do not use QQmlEngine from current QML context
We cannot be sure the current context is still alive when a function is
called. We may be left with a skeleton context that doesn't have an
engine anymore.
However, we can always query the QJSEngine given in the AOT context.
That one cannot disappear and is generally the right one for capturing
properties.
Pick-to: 6.7 6.5 6.2
Fixes: QTBUG-123395
Change-Id: I2a6c38baa159fa790f3ba2aba225fdc9cc37001e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 4c33098235..475cb8eee6 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -2237,6 +2237,18 @@ void tst_QmlCppCodegen::idAccess() QObject *ttt = qmlContext(object.data())->objectForName(u"ttt"_s); QFont f = qvariant_cast<QFont>(ttt->property("font")); QCOMPARE(f.pointSize(), 22); + + QObject::connect(object.data(), &QObject::objectNameChanged, ttt, [&](){ + ttt->setParent(nullptr); + QJSEngine::setObjectOwnership(ttt, QJSEngine::CppOwnership); + object.reset(ttt); + }); + + QVERIFY(object->objectName().isEmpty()); + QVERIFY(ttt->objectName().isEmpty()); + ttt->setProperty("text", u"kill"_s); + QCOMPARE(object.data(), ttt); + QCOMPARE(ttt->objectName(), u"context"_s); } void tst_QmlCppCodegen::ignoredFunctionReturn() |
