diff --git a/src/libs/qmljs/qmljsinterpreter.cpp b/src/libs/qmljs/qmljsinterpreter.cpp index ae8c1009723..24d68d4948e 100644 --- a/src/libs/qmljs/qmljsinterpreter.cpp +++ b/src/libs/qmljs/qmljsinterpreter.cpp @@ -39,6 +39,7 @@ #include +#include #include #include #include @@ -1253,7 +1254,8 @@ CppQmlTypesLoader::BuiltinObjects CppQmlTypesLoader::loadQmlTypes(const QFileInf QByteArray contents = file.readAll(); file.close(); - parseQmlTypeDescriptions(contents, &newObjects, 0, &error, &warning); + + parseQmlTypeDescriptions(contents, &newObjects, 0, &error, &warning, qmlTypeFile.absoluteFilePath()); } else { error = file.errorString(); } @@ -1272,15 +1274,28 @@ CppQmlTypesLoader::BuiltinObjects CppQmlTypesLoader::loadQmlTypes(const QFileInf return newObjects; } -void CppQmlTypesLoader::parseQmlTypeDescriptions(const QByteArray &xml, +void CppQmlTypesLoader::parseQmlTypeDescriptions(const QByteArray &contents, BuiltinObjects *newObjects, QList *newModuleApis, QString *errorMessage, - QString *warningMessage) + QString *warningMessage, const QString &fileName) { + if (!contents.isEmpty()) { + unsigned char c = contents.at(0); + switch (c) { + case 0xfe: + case 0xef: + case 0xff: + case 0xee: + case 0x00: + qWarning() << QApplication::translate("CppQmlTypesLoader", "%1 seems not to be encoded in UTF8 or has a BOM.").arg(fileName); + default: break; + } + } + errorMessage->clear(); warningMessage->clear(); - TypeDescriptionReader reader(QString::fromUtf8(xml)); + TypeDescriptionReader reader(QString::fromUtf8(contents)); if (!reader(newObjects, newModuleApis)) { if (reader.errorMessage().isEmpty()) *errorMessage = QLatin1String("unknown error"); diff --git a/src/libs/qmljs/qmljsinterpreter.h b/src/libs/qmljs/qmljsinterpreter.h index 4eddbf64560..56f914713f1 100644 --- a/src/libs/qmljs/qmljsinterpreter.h +++ b/src/libs/qmljs/qmljsinterpreter.h @@ -608,10 +608,9 @@ public: static BuiltinObjects defaultLibraryObjects; // parses the contents of a qmltypes file and fills the newObjects map - static void parseQmlTypeDescriptions( - const QByteArray &qmlTypes, + static void parseQmlTypeDescriptions(const QByteArray &contents, BuiltinObjects *newObjects, - QList *newModuleApis, QString *errorMessage, QString *warningMessage); + QList *newModuleApis, QString *errorMessage, QString *warningMessage, const QString &fileName); }; class QMLJS_EXPORT CppQmlTypes diff --git a/src/plugins/qmljstools/qmljsplugindumper.cpp b/src/plugins/qmljstools/qmljsplugindumper.cpp index cfb47d9001b..5338220afcf 100644 --- a/src/plugins/qmljstools/qmljsplugindumper.cpp +++ b/src/plugins/qmljstools/qmljsplugindumper.cpp @@ -326,7 +326,8 @@ void PluginDumper::qmlPluginTypeDumpDone(int exitCode) QString warning; CppQmlTypesLoader::BuiltinObjects objectsList; QList moduleApis; - CppQmlTypesLoader::parseQmlTypeDescriptions(output, &objectsList, &moduleApis, &error, &warning); + CppQmlTypesLoader::parseQmlTypeDescriptions(output, &objectsList, &moduleApis, &error, &warning, + QLatin1String("")); if (exitCode == 0) { if (!error.isEmpty()) { libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError, @@ -397,7 +398,7 @@ void PluginDumper::loadQmltypesFile(const QStringList &qmltypesFilePaths, QString warning; CppQmlTypesLoader::BuiltinObjects newObjects; QList newModuleApis; - CppQmlTypesLoader::parseQmlTypeDescriptions(reader.data(), &newObjects, &newModuleApis, &error, &warning); + CppQmlTypesLoader::parseQmlTypeDescriptions(reader.data(), &newObjects, &newModuleApis, &error, &warning, qmltypesFilePath); if (!error.isEmpty()) { errors += tr("Failed to parse '%1'.\nError: %2").arg(qmltypesFilePath, error); } else {