aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <[email protected]>2025-04-08 12:53:02 +0200
committerUlf Hermann <[email protected]>2025-04-10 13:35:01 +0200
commit618720a3a9a7c3e292ed5fb6792ca4069c90f443 (patch)
tree50b3f2015d325d00c0225dd5d86fc511123120f7
parente84635f9239673592f44df99d3e0f9b65a1d97f0 (diff)
QmlPreview: Drop existing CUs when replacing a file
When the client wants us to use a new version of the file we shouldn't let the already existing compilation units get in the way. Amends commit 6468df7657f6af4de8727363c7f7d97b680b1867 Pick-to: 6.9 6.8 Fixes: QTBUG-129329 Change-Id: Ic4b6a0194d58412e213688959251209a94ef50f3 Reviewed-by: Sami Shalayel <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]>
-rw-r--r--src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.cpp14
-rw-r--r--tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp26
2 files changed, 36 insertions, 4 deletions
diff --git a/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.cpp b/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.cpp
index ea82bf0c5b..b5b5c8b5c9 100644
--- a/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.cpp
+++ b/src/plugins/qmltooling/qmldbg_preview/qqmlpreviewservice.cpp
@@ -46,16 +46,22 @@ void QQmlPreviewServiceImpl::messageReceived(const QByteArray &data)
QString path;
QByteArray contents;
packet >> path >> contents;
+
+ const QUrl url = path.startsWith(QLatin1Char(':'))
+ ? QUrl(QLatin1String("qrc") + path)
+ : QUrl::fromLocalFile(path);
+
+ // Drop any existing compilation units for this URL from the type registry.
+ if (const auto cu = QQmlMetaType::obtainCompilationUnit(url))
+ QQmlMetaType::unregisterInternalCompositeType(cu);
+
emit file(path, contents);
// Replace the whole scene with the first file successfully loaded over the debug
// connection. This is an OK approximation of the root component, and if the client wants
// something specific, it will send an explicit Load anyway.
if (m_currentUrl.isEmpty() && path.endsWith(".qml")) {
- if (path.startsWith(':'))
- m_currentUrl = QUrl("qrc" + path);
- else
- m_currentUrl = QUrl::fromLocalFile(path);
+ m_currentUrl = url;
emit load(m_currentUrl);
}
break;
diff --git a/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp b/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp
index d1d5964b5f..594da185a1 100644
--- a/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp
+++ b/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp
@@ -52,6 +52,7 @@ private slots:
void fps();
void unhandledFiles_data();
void unhandledFiles();
+ void updateFile();
};
tst_QQmlPreview::tst_QQmlPreview()
@@ -399,6 +400,31 @@ void tst_QQmlPreview::unhandledFiles()
QVERIFY(!m_files.contains(file.toLocalFile()));
}
+void tst_QQmlPreview::updateFile()
+{
+ const QString file("qtquick2.qml");
+ QCOMPARE(startQmlProcess(file), ConnectSuccess);
+ QVERIFY(m_client);
+ QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled);
+ m_client->triggerLoad(testFileUrl(file));
+ QTRY_VERIFY(m_files.contains(testFile(file)));
+ verifyProcessOutputContains("ms/degrees");
+
+ QFile input(testFile(file));
+ QVERIFY(input.open(QIODevice::ReadOnly));
+ QByteArray contents = input.readAll();
+ contents.replace("ms/degrees", "foozle/barzle");
+ contents.replace("blue", "red");
+
+ serveFile(testFile(file), contents);
+ m_client->triggerLoad(testFileUrl(file));
+ verifyProcessOutputContains("foozle/barzle");
+
+ m_process->stop();
+ QTRY_COMPARE(m_client->state(), QQmlDebugClient::NotConnected);
+ QVERIFY(m_serviceErrors.isEmpty());
+}
+
QTEST_MAIN(tst_QQmlPreview)
#include "tst_qqmlpreview.moc"