diff --git a/src/tools/moc/main.cpp b/src/tools/moc/main.cpp index 472dac38039..3c49128476d 100644 --- a/src/tools/moc/main.cpp +++ b/src/tools/moc/main.cpp @@ -285,6 +285,10 @@ int runMoc(int argc, char **argv) activeQtMode.setFlags(QCommandLineOption::HiddenFromHelp); parser.addOption(activeQtMode); + QCommandLineOption qmlMacroWarningIsFatal(QStringLiteral("fatal-qml-macro-warning")); + qmlMacroWarningIsFatal.setFlags(QCommandLineOption::HiddenFromHelp); + parser.addOption(qmlMacroWarningIsFatal); + QCommandLineOption noNotesOption(QStringLiteral("no-notes")); noNotesOption.setDescription(QStringLiteral("Do not display notes.")); parser.addOption(noNotesOption); @@ -448,6 +452,8 @@ int runMoc(int argc, char **argv) moc.displayNotes = false; if (parser.isSet(noWarningsOption) || noNotesCompatValues.contains("w"_L1)) moc.displayWarnings = moc.displayNotes = false; + if (parser.isSet(qmlMacroWarningIsFatal)) + moc.qmlMacroWarningIsFatal = true; if (autoInclude) { qsizetype spos = filename.lastIndexOf(QDir::separator()); diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 27655dbe2aa..da0096ebfe1 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -1044,7 +1044,10 @@ void Moc::parse() QByteArray msg("Potential QML registration macro was found, but no header containing it was included.\n" "This might cause runtime errors in QML applications\n" "Include or to fix this."); - warning(qmlRegistrationMacroSymbol, msg.constData()); + if (qmlMacroWarningIsFatal) + error(qmlRegistrationMacroSymbol, msg.constData()); + else + warning(qmlRegistrationMacroSymbol, msg.constData()); } if (!def.hasQObject && !def.hasQGadget && def.signalList.isEmpty() && def.slotList.isEmpty() diff --git a/src/tools/moc/parser.h b/src/tools/moc/parser.h index 526364d7d96..56e95a3f08c 100644 --- a/src/tools/moc/parser.h +++ b/src/tools/moc/parser.h @@ -19,6 +19,7 @@ public: bool displayWarnings = true; bool displayNotes = true; bool activeQtMode = false; + bool qmlMacroWarningIsFatal = false; struct IncludePath { diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index c46bcae7b23..fa256d24c7d 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -786,6 +786,7 @@ private slots: void dontStripNamespaces(); void oldStyleCasts(); + void faultyQmlRegistration_data(); void faultyQmlRegistration(); void warnOnExtraSignalSlotQualifiaction(); void uLongLong(); @@ -1021,16 +1022,30 @@ void tst_Moc::oldStyleCasts() #endif } +void tst_Moc::faultyQmlRegistration_data() +{ + QTest::addColumn("qmlWarningIsFatal"); + QTest::addColumn("exitCode"); + + QTest::newRow("normal") << false << EXIT_SUCCESS; + QTest::newRow("fatalWarning") << true << EXIT_FAILURE; +} + void tst_Moc::faultyQmlRegistration() { #ifdef MOC_CROSS_COMPILED QSKIP("Not tested when cross-compiled"); #endif #if QT_CONFIG(process) + QFETCH(bool, qmlWarningIsFatal); + QFETCH(int, exitCode); QProcess proc; - proc.start(m_moc, QStringList(m_sourceDirectory + QStringLiteral("/faulty_qml_registration/faulty_registration.h"))); + auto cmd = QStringList(m_sourceDirectory + QStringLiteral("/faulty_qml_registration/faulty_registration.h")); + if (qmlWarningIsFatal) + cmd += QStringLiteral("--fatal-qml-macro-warning"); + proc.start(m_moc, cmd); QVERIFY(proc.waitForFinished()); - QCOMPARE(proc.exitCode(), 0); + QCOMPARE(proc.exitCode(), exitCode); QByteArray errorMsg = proc.readAllStandardError(); QVERIFY2(errorMsg.contains("QML registration macro"), errorMsg.constData()); #else