aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2026-09-24 09:36:59 +0200
committerUlf Hermann <ulf.hermann@qt.io>2026-09-25 13:50:05 +0000
commitb200faedd4026bbfa8cbb12c7374f30c1a87e075 (patch)
tree9c64c28d5f4c9858f9b40baa9c6521c7578bff33
parentcddeb0d720e19322b459de35c73b4395da64929d (diff)
qmlpreview: Don't duplicate arguments on every restart
Amends commit 265c9250df853df1110ca4c2545b100481b98a2e. Pick-to: 6.12 Change-Id: Ibe18bc49a59e93a48341d204dcc238f366d60e55 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
-rw-r--r--tests/auto/qml/debugger/qmlpreviewtool/tst_qmlpreviewtool.cpp46
-rw-r--r--tools/qmlpreview/qmlpreviewapplication.cpp7
2 files changed, 50 insertions, 3 deletions
diff --git a/tests/auto/qml/debugger/qmlpreviewtool/tst_qmlpreviewtool.cpp b/tests/auto/qml/debugger/qmlpreviewtool/tst_qmlpreviewtool.cpp
index 1de1271fe0..d1a4416b2e 100644
--- a/tests/auto/qml/debugger/qmlpreviewtool/tst_qmlpreviewtool.cpp
+++ b/tests/auto/qml/debugger/qmlpreviewtool/tst_qmlpreviewtool.cpp
@@ -35,6 +35,7 @@ private slots:
void inputNotReplayedOnHotReload();
void hotReloadFailure();
void interactiveCommands();
+ void restartKeepsArguments();
void saveAndReplayRoundTrip();
void classicModeReplaysRecordedInput();
@@ -584,6 +585,51 @@ void tst_QmlPreviewTool::interactiveCommands()
QCOMPARE(m_process.exitCode(), 0);
}
+// Restarting the target must launch it with the same arguments as the first
+// time. Before the fix, every (re)start appended another -qmljsdebugger option
+// to the stored arguments, so they piled up with each restart.
+void tst_QmlPreviewTool::restartKeepsArguments()
+{
+ m_tempDir = std::make_unique<QTemporaryDir>();
+ QVERIFY(m_tempDir->isValid());
+
+ const QString qmlFile = m_tempDir->filePath(QLatin1String("test.qml"));
+ QVERIFY(writeFile(qmlFile, makeQmlContent(QLatin1String("RESTART_OK"))));
+
+ startPreview({ QLatin1String("--interactive"), QLatin1String("--verbose"), m_qmlRuntimePath,
+ qmlFile });
+ QVERIFY2(waitForOutput(QLatin1String("RESTART_OK")),
+ qPrintable(QLatin1String("Initial load failed. Output:\n") + m_output));
+
+ const QLatin1String starting("Starting '");
+ for (int restarts = 1; restarts <= 2; ++restarts) {
+ sendCommand(QLatin1String("restart"));
+
+ // Wait for the restarted target to be up, so that the next restart
+ // doesn't overtake this one.
+ const bool restarted = QTest::qWaitFor([this, &starting, restarts]() {
+ readProcessOutput();
+ if (m_output.count(starting) != restarts + 1)
+ return false;
+ return m_output.indexOf(QLatin1String("RESTART_OK"), m_output.lastIndexOf(starting))
+ != -1;
+ }, 30000);
+ QVERIFY2(restarted,
+ qPrintable(QLatin1String("Target was not restarted. Output:\n") + m_output));
+ }
+
+ const QStringList lines = m_output.split(QLatin1Char('\n'));
+ qsizetype launches = 0;
+ for (const QString &line : lines) {
+ if (!line.startsWith(starting))
+ continue;
+ ++launches;
+ QVERIFY2(line.contains(qmlFile), qPrintable(line));
+ QCOMPARE(line.count(QLatin1String("-qmljsdebugger=")), 1);
+ }
+ QCOMPARE(launches, 3);
+}
+
// End-to-end round trip: record the input event stream of one session to a .qtd
// file, then load it in the next session and replay it to restore the UI state.
void tst_QmlPreviewTool::saveAndReplayRoundTrip()
diff --git a/tools/qmlpreview/qmlpreviewapplication.cpp b/tools/qmlpreview/qmlpreviewapplication.cpp
index de21066a9e..6e327dc589 100644
--- a/tools/qmlpreview/qmlpreviewapplication.cpp
+++ b/tools/qmlpreview/qmlpreviewapplication.cpp
@@ -401,10 +401,11 @@ void QmlPreviewApplication::startProcess()
this, &QmlPreviewApplication::processHasOutput);
connect(m_process.data(), QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, [this](int){ processFinished(); });
- m_arguments.append(makeQmlPreviewArgument(m_socketFile));
+ QStringList arguments = m_arguments;
+ arguments.append(makeQmlPreviewArgument(m_socketFile));
logStatus(QString("Starting '%1 %2' ...")
- .arg(m_executablePath, m_arguments.join(QLatin1Char(' '))));
- m_process->start(m_executablePath, m_arguments);
+ .arg(m_executablePath, arguments.join(QLatin1Char(' '))));
+ m_process->start(m_executablePath, arguments);
if (!m_process->waitForStarted()) {
logError(QString("Could not run '%1': %2").arg(m_executablePath, m_process->errorString()));
exit(1);