aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-08-15 10:30:44 +0200
committerUlf Hermann <ulf.hermann@qt.io>2023-08-15 17:48:43 +0200
commitf6735dba9518ffc896541f212fade350e18c91de (patch)
tree747b22fbd78c504b2d05acbbe90c849bf62e0d1a /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parentafb57dfa06fb7e8be47ac1118758421cfe31ba3e (diff)
QmlCompiler: Fix console logging
Store a copy of the UTF-8 data for file and function so that we don't run into heap-use-after-free. Set the instruction pointer before calling the log function so that we get a correct line number. Pick-to: 6.6 6.5 Fixes: QTBUG-114655 Change-Id: I38249fe52719ddad620033716ff22b2087ab8382 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.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index f7f2182796..a42491c12a 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -993,7 +993,8 @@ void tst_QmlCppCodegen::compositeTypeMethod()
void tst_QmlCppCodegen::consoleObject()
{
QQmlEngine engine;
- QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/consoleObject.qml"_s));
+ static const QString urlString = u"qrc:/qt/qml/TestTypes/consoleObject.qml"_s;
+ QQmlComponent c(&engine, QUrl(urlString));
QVERIFY2(c.isReady(), qPrintable(c.errorString()));
QTest::ignoreMessage(QtDebugMsg, "b 4.55");
@@ -1026,6 +1027,17 @@ void tst_QmlCppCodegen::consoleObject()
QScopedPointer<QObject> o(c.create());
QVERIFY(!o.isNull());
+
+ auto oldHandler = qInstallMessageHandler(
+ [](QtMsgType, const QMessageLogContext &ctxt, const QString &) {
+ QCOMPARE(ctxt.file, urlString.toUtf8());
+ QCOMPARE(ctxt.function, QByteArray("expression for onCompleted"));
+ QVERIFY(ctxt.line > 0);
+ });
+ const auto guard = qScopeGuard([oldHandler]() { qInstallMessageHandler(oldHandler); });
+
+ QScopedPointer<QObject> p(c.create());
+ QVERIFY(!p.isNull());
}
void tst_QmlCppCodegen::construct()