summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tools/moc/moc.cpp7
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp16
2 files changed, 22 insertions, 1 deletions
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp
index 03f022da69..e2987f1be4 100644
--- a/src/tools/moc/moc.cpp
+++ b/src/tools/moc/moc.cpp
@@ -1294,7 +1294,12 @@ void Moc::parsePluginData(ClassDef *def)
return;
}
QFile file(fi.canonicalFilePath());
- file.open(QFile::ReadOnly);
+ if (!file.open(QFile::ReadOnly)) {
+ QByteArray msg = "Plugin Metadata file " + lexem() + " could not be opened: "
+ + file.errorString().toUtf8();
+ error(msg.constData());
+ return;
+ }
metaData = file.readAll();
}
}
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index ecf6c7e992..e704a6877e 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -2145,6 +2145,22 @@ void tst_Moc::warnings_data()
<< 0
<< QString()
<< QString("standard input:1: Note: No relevant classes found. No output generated.");
+
+ QTest::newRow("Q_PLUGIN_METADATA: invalid file")
+ << QByteArray("class X { \n Q_PLUGIN_METADATA(FILE \"does.not.exists\") \n };")
+ << QStringList()
+ << 1
+ << QString()
+ << QString("standard input:2: Error: Plugin Metadata file \"does.not.exists\" does not exist. Declaration will be ignored");
+
+#ifdef Q_OS_LINUX // Limit to Linux because the error message is platform-dependent
+ QTest::newRow("Q_PLUGIN_METADATA: unreadable file")
+ << QByteArray("class X { \n Q_PLUGIN_METADATA(FILE \".\") \n };")
+ << QStringList()
+ << 1
+ << QString()
+ << QString("standard input:2: Error: Plugin Metadata file \".\" could not be opened: file to open is a directory");
+#endif
}
void tst_Moc::warnings()