qml-tool: Treat all arguments passed after "--" as positional

The argument "-a" passed after "--" was being interpreted as the -a
option of the qml tool itself instead of being passed along to the qml
program as a positional argument.

Fixes: QTBUG-136120
Pick-to: 6.9 6.8 6.5
Change-Id: I602aea84e4766abeb47adce0f739f12315a70b24
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Olivier De Cannière 2025-04-23 10:58:49 +02:00
parent 9bebb7017b
commit 6ac4833a51
2 changed files with 38 additions and 0 deletions

View File

@ -9,6 +9,8 @@
#include <QtGui/qpa/qplatformintegration.h> #include <QtGui/qpa/qplatformintegration.h>
#include <QtQuickTestUtils/private/qmlutils_p.h> #include <QtQuickTestUtils/private/qmlutils_p.h>
#include <QTemporaryFile>
Q_LOGGING_CATEGORY(lcQml, "qt.qml.tests"); Q_LOGGING_CATEGORY(lcQml, "qt.qml.tests");
class tst_qml : public QQmlDataTest class tst_qml : public QQmlDataTest
@ -22,6 +24,7 @@ private slots:
void nonWindow(); void nonWindow();
void itemAndWindowGeometry_data(); void itemAndWindowGeometry_data();
void itemAndWindowGeometry(); void itemAndWindowGeometry();
void extraPositionalArguments();
private: private:
QString qmlPath; QString qmlPath;
@ -175,6 +178,38 @@ void tst_qml::itemAndWindowGeometry()
QCOMPARE(contentSize, expectedContentSize); QCOMPARE(contentSize, expectedContentSize);
} }
void tst_qml::extraPositionalArguments()
{
QProcess qml;
QStringList args;
QTemporaryFile f;
QVERIFY(f.open());
QVERIFY(f.write(R"(import QtQml
QtObject {
Component.onCompleted: {
let s = ""
for (let i = 2; i < Qt.application.arguments.length; ++i)
s += Qt.application.arguments[i].substring(1)
console.log(s)
Qt.quit()
}
}
)"));
f.flush();
args << f.fileName();
args << "--";
for (char c = 'a'; c <= 'z'; ++c)
args << u'-' + QString(c);
qml.start(qmlPath, args);
QVERIFY(qml.waitForFinished());
QVERIFY(qml.exitStatus() == QProcess::NormalExit && qml.exitCode() == 0);
QVERIFY(qml.readAllStandardError().contains("abcdefghijklmnopqrstuvwxyz"));
}
QTEST_MAIN(tst_qml) QTEST_MAIN(tst_qml)
#include <tst_qml.moc> #include <tst_qml.moc>

View File

@ -318,6 +318,9 @@ static void getAppFlags(int argc, char **argv)
{ {
#ifdef QT_GUI_LIB #ifdef QT_GUI_LIB
for (int i=0; i<argc; i++) { for (int i=0; i<argc; i++) {
if (strcmp(argv[i], "--"))
return; // After "--", arguments are interpreted as positional and not as options.
if (!strcmp(argv[i], "--apptype") || !strcmp(argv[i], "-a") || !strcmp(argv[i], "-apptype")) { if (!strcmp(argv[i], "--apptype") || !strcmp(argv[i], "-a") || !strcmp(argv[i], "-apptype")) {
applicationType = QmlApplicationTypeUnknown; applicationType = QmlApplicationTypeUnknown;
if (i+1 < argc) { if (i+1 < argc) {