qmltyperegistrar: Make warnings and errors legible to Qt Creator
Qt Creator expects a specific output format from "Qt like" tools. We cannot give it line numbers, yet, because moc does not supply them. It could, though. Therefore, we reserve the space between the double colons to add line numbers later. Fixes: QTBUG-118792 Change-Id: Iad8e3b1cbd54fc6b315179da9968913da4d4f8e0 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
364abd8817
commit
c12e55dbd3
|
@ -6,6 +6,7 @@
|
|||
#include "qanystringviewutils_p.h"
|
||||
#include "qqmltyperegistrarconstants_p.h"
|
||||
#include "qqmltypesclassdescription_p.h"
|
||||
#include "qqmltyperegistrarutils_p.h"
|
||||
|
||||
#include <QtCore/qcborarray.h>
|
||||
#include <QtCore/qcbormap.h>
|
||||
|
@ -53,14 +54,15 @@ bool MetaTypesJsonProcessor::processTypes(const QStringList &files)
|
|||
{
|
||||
QFile f(source);
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
fprintf(stderr, "Error opening %s for reading\n", qPrintable(source));
|
||||
error(source) << "Cannot open file for reading";
|
||||
return false;
|
||||
}
|
||||
QJsonParseError error = {0, QJsonParseError::NoError};
|
||||
metaObjects = fromJson(f.readAll(), &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
fprintf(stderr, "Error %d while parsing %s: %s\n", error.error, qPrintable(source),
|
||||
qPrintable(error.errorString()));
|
||||
QJsonParseError parseError = {0, QJsonParseError::NoError};
|
||||
metaObjects = fromJson(f.readAll(), &parseError);
|
||||
if (parseError.error != QJsonParseError::NoError) {
|
||||
error(source)
|
||||
<< "Failed to parse JSON:" << parseError.error
|
||||
<< parseError.errorString();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -69,8 +71,7 @@ bool MetaTypesJsonProcessor::processTypes(const QStringList &files)
|
|||
const QCborArray metaObjectsArray = metaObjects.toArray();
|
||||
for (const QCborValue &metaObject : metaObjectsArray) {
|
||||
if (!metaObject.isMap()) {
|
||||
fprintf(stderr, "Error parsing %s: JSON is not an object\n",
|
||||
qPrintable(source));
|
||||
error(source) << "JSON is not an object";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -79,8 +80,7 @@ bool MetaTypesJsonProcessor::processTypes(const QStringList &files)
|
|||
} else if (metaObjects.isMap()) {
|
||||
processTypes(metaObjects.toMap());
|
||||
} else {
|
||||
fprintf(stderr, "Error parsing %s: JSON is not an object or an array\n",
|
||||
qPrintable(source));
|
||||
error(source) << "JSON is not an object or an array";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -92,23 +92,23 @@ bool MetaTypesJsonProcessor::processForeignTypes(const QString &types)
|
|||
{
|
||||
QFile typesFile(types);
|
||||
if (!typesFile.open(QIODevice::ReadOnly)) {
|
||||
fprintf(stderr, "Cannot open foreign types file %s\n", qPrintable(types));
|
||||
error(types) << "Cannot open foreign types file";
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonParseError error = {0, QJsonParseError::NoError};
|
||||
QCborValue foreignMetaObjects = fromJson(typesFile.readAll(), &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
fprintf(stderr, "Error %d while parsing %s: %s\n", error.error, qPrintable(types),
|
||||
qPrintable(error.errorString()));
|
||||
QJsonParseError parseError = {0, QJsonParseError::NoError};
|
||||
QCborValue foreignMetaObjects = fromJson(typesFile.readAll(), &parseError);
|
||||
if (parseError.error != QJsonParseError::NoError) {
|
||||
error(types)
|
||||
<< "Failed to parse JSON:" << parseError.error
|
||||
<< parseError.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
const QCborArray foreignObjectsArray = foreignMetaObjects.toArray();
|
||||
for (const QCborValue &metaObject : foreignObjectsArray) {
|
||||
if (!metaObject.isMap()) {
|
||||
fprintf(stderr, "Error parsing %s: JSON is not an object\n",
|
||||
qPrintable(types));
|
||||
error(types) << "JSON is not an object";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -219,9 +219,10 @@ MetaTypesJsonProcessor::RegistrationMode MetaTypesJsonProcessor::qmlTypeRegistra
|
|||
return GadgetRegistration;
|
||||
if (classDef[S_NAMESPACE].toBool())
|
||||
return NamespaceRegistration;
|
||||
qWarning() << "Not registering classInfo which is neither an object, "
|
||||
"nor a gadget, nor a namespace:"
|
||||
<< name.toString();
|
||||
warning(classDef)
|
||||
<< "Not registering a classInfo which is neither an object,"
|
||||
<< "nor a gadget, nor a namespace:"
|
||||
<< name.toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -440,11 +441,10 @@ void MetaTypesJsonProcessor::processTypes(const QCborMap &types)
|
|||
&& !endsWith(include, QLatin1String(".hh"))
|
||||
&& !endsWith(include, QLatin1String(".py"))
|
||||
&& contains(include, QLatin1Char('.'))) {
|
||||
fprintf(stderr,
|
||||
"Class %s is declared in %s, which appears not to be a header.\n"
|
||||
"The compilation of its registration to QML may fail.\n",
|
||||
qPrintable(classDef.value(S_QUALIFIED_CLASS_NAME).toString()),
|
||||
qPrintable(include));
|
||||
warning(classDef)
|
||||
<< "Class" << toStringView(classDef, S_QUALIFIED_CLASS_NAME)
|
||||
<< "is declared in" << include << "which appears not to be a header."
|
||||
<< "The compilation of its registration to QML may fail.";
|
||||
}
|
||||
m_includes.append(include);
|
||||
m_types.append(classDef);
|
||||
|
|
|
@ -20,6 +20,7 @@ using namespace QAnyStringViewUtils;
|
|||
|
||||
struct ExclusiveVersionRange
|
||||
{
|
||||
QAnyStringView fileName;
|
||||
QString claimerName;
|
||||
QTypeRevision addedIn;
|
||||
QTypeRevision removedIn;
|
||||
|
@ -58,12 +59,12 @@ bool QmlTypeRegistrar::argumentsFromCommandLineAndFile(QStringList &allArguments
|
|||
QString optionsFile = argument;
|
||||
optionsFile.remove(0, 1);
|
||||
if (optionsFile.isEmpty()) {
|
||||
fprintf(stderr, "The @ option requires an input file");
|
||||
warning(optionsFile) << "The @ option requires an input file";
|
||||
return false;
|
||||
}
|
||||
QFile f(optionsFile);
|
||||
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
fprintf(stderr, "Cannot open options file specified with @");
|
||||
warning(optionsFile) << "Cannot open options file specified with @";
|
||||
return false;
|
||||
}
|
||||
while (!f.atEnd()) {
|
||||
|
@ -81,13 +82,13 @@ bool QmlTypeRegistrar::argumentsFromCommandLineAndFile(QStringList &allArguments
|
|||
int QmlTypeRegistrar::runExtract(const QString &baseName, const MetaTypesJsonProcessor &processor)
|
||||
{
|
||||
if (processor.types().isEmpty()) {
|
||||
fprintf(stderr, "Error: No types to register found in library\n");
|
||||
error(baseName) << "No types to register found in library";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
QFile headerFile(baseName + u".h");
|
||||
bool ok = headerFile.open(QFile::WriteOnly);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error: Cannot open %s for writing\n", qPrintable(headerFile.fileName()));
|
||||
error(headerFile.fileName()) << "Cannot open header file for writing";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
auto prefix = QString::fromLatin1(
|
||||
|
@ -103,7 +104,7 @@ int QmlTypeRegistrar::runExtract(const QString &baseName, const MetaTypesJsonPro
|
|||
QFile sourceFile(baseName + u".cpp");
|
||||
ok = sourceFile.open(QFile::WriteOnly);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error: Cannot open %s for writing\n", qPrintable(sourceFile.fileName()));
|
||||
error(sourceFile.fileName()) << "Cannot open implementation file for writing";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// the string split is necessaury because cmake's automoc scanner would otherwise pick up the include
|
||||
|
@ -148,7 +149,7 @@ QString conflictingVersionToString(const ExclusiveVersionRange &r)
|
|||
return s;
|
||||
};
|
||||
|
||||
void QmlTypeRegistrar::write(QTextStream &output)
|
||||
void QmlTypeRegistrar::write(QTextStream &output, QAnyStringView outFileName)
|
||||
{
|
||||
output << uR"(/****************************************************************************
|
||||
** Generated QML type registration code
|
||||
|
@ -177,7 +178,7 @@ void QmlTypeRegistrar::write(QTextStream &output)
|
|||
if (underscoredModuleAsSymbol != moduleAsSymbol
|
||||
|| underscoredModuleAsSymbol.isEmpty()
|
||||
|| underscoredModuleAsSymbol.front().isDigit()) {
|
||||
qWarning() << m_module << "is an invalid QML module URI. You cannot import this.";
|
||||
warning(outFileName) << m_module << "is an invalid QML module URI. You cannot import this.";
|
||||
}
|
||||
|
||||
const QString functionName = QStringLiteral("qml_register_types_") + moduleAsSymbol;
|
||||
|
@ -218,7 +219,7 @@ void QmlTypeRegistrar::write(QTextStream &output)
|
|||
if (toStringView(classDef, S_INPUT_FILE).isEmpty())
|
||||
continue;
|
||||
|
||||
const QString className = classDef[S_QUALIFIED_CLASS_NAME].toString();
|
||||
QString className = classDef[S_QUALIFIED_CLASS_NAME].toString();
|
||||
QString targetName = className;
|
||||
|
||||
// If either the foreign or the local part is a namespace we need to
|
||||
|
@ -226,7 +227,7 @@ void QmlTypeRegistrar::write(QTextStream &output)
|
|||
bool targetIsNamespace = classDef.value(S_NAMESPACE).toBool();
|
||||
|
||||
QAnyStringView extendedName;
|
||||
QStringList qmlElementNames;
|
||||
QList<QString> qmlElementNames;
|
||||
QTypeRevision addedIn;
|
||||
QTypeRevision removedIn;
|
||||
|
||||
|
@ -253,12 +254,17 @@ void QmlTypeRegistrar::write(QTextStream &output)
|
|||
}
|
||||
}
|
||||
|
||||
for (QString &qmlElementName : qmlElementNames) {
|
||||
for (QString qmlElementName : std::as_const(qmlElementNames)) {
|
||||
if (qmlElementName == S_ANONYMOUS)
|
||||
continue;
|
||||
if (qmlElementName == S_AUTO)
|
||||
qmlElementName = className;
|
||||
qmlElementInfos[qmlElementName].append({ className, addedIn, removedIn });
|
||||
qmlElementInfos[qmlElementName].append({
|
||||
toStringView(classDef, S_INPUT_FILE),
|
||||
className,
|
||||
addedIn,
|
||||
removedIn
|
||||
});
|
||||
}
|
||||
|
||||
// We want all related metatypes to be registered by name, so that we can look them up
|
||||
|
@ -277,10 +283,10 @@ void QmlTypeRegistrar::write(QTextStream &output)
|
|||
m_types, m_foreignTypes, targetName, namespaces);
|
||||
|
||||
if (!target.javaScript.isEmpty() && target.native.isEmpty())
|
||||
qWarning() << "JavaScript type" << targetName << "cannot be used as namespace";
|
||||
warning(target.javaScript) << "JavaScript type cannot be used as namespace";
|
||||
|
||||
if (target.native.value(S_OBJECT).toBool())
|
||||
targetTypeName += QStringLiteral(" *");
|
||||
targetTypeName += " *"_L1;
|
||||
|
||||
// If there is no foreign type, the local one is a namespace.
|
||||
// Otherwise, only do metaTypeForNamespace if the target _metaobject_ is a namespace.
|
||||
|
@ -328,9 +334,9 @@ void QmlTypeRegistrar::write(QTextStream &output)
|
|||
QTypeRevision revision = QTypeRevision::fromEncodedVersion(
|
||||
object[S_REVISION].toInteger());
|
||||
if (m_moduleVersion < revision) {
|
||||
qWarning().noquote()
|
||||
<< "Warning:" << className << "is trying to register" << type
|
||||
<< object[S_NAME].toString()
|
||||
warning(classDef)
|
||||
<< className << "is trying to register" << type
|
||||
<< toStringView(object, S_NAME)
|
||||
<< "with future version" << revision
|
||||
<< "when module version is only" << m_moduleVersion;
|
||||
}
|
||||
|
@ -453,9 +459,9 @@ void QmlTypeRegistrar::write(QTextStream &output)
|
|||
[&](const auto &q) {
|
||||
registeringCppClasses += u", %1"_s.arg(conflictingVersionToString(q));
|
||||
});
|
||||
qWarning().noquote() << "Warning:" << qmlName
|
||||
<< "was registered multiple times by following Cpp classes: "
|
||||
<< registeringCppClasses;
|
||||
warning(conflictingExportStartIt->fileName)
|
||||
<< qmlName << "is registered multiple times by the following C++ classes:"
|
||||
<< registeringCppClasses;
|
||||
conflictingExportStartIt = conflictingExportEndIt;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class QmlTypeRegistrar
|
|||
QCborValue findTypeForeign(QAnyStringView name) const;
|
||||
|
||||
public:
|
||||
void write(QTextStream &os);
|
||||
void write(QTextStream &os, QAnyStringView outFileName);
|
||||
bool generatePluginTypes(const QString &pluginTypesFile);
|
||||
void setModuleNameAndNamespace(const QString &module, const QString &targetNamespace);
|
||||
void setModuleVersions(QTypeRevision moduleVersion, const QList<quint8> &pastMajorVersions,
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "qanystringviewutils_p.h"
|
||||
#include "qqmltyperegistrarconstants_p.h"
|
||||
#include "qqmltyperegistrarutils_p.h"
|
||||
|
||||
#include <QtCore/qdebug.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QTypeRevision handleInMinorVersion(QTypeRevision revision, int majorVersion)
|
||||
|
@ -14,4 +18,35 @@ QTypeRevision handleInMinorVersion(QTypeRevision revision, int majorVersion)
|
|||
return revision;
|
||||
}
|
||||
|
||||
|
||||
static QDebug message(QDebug base, QAnyStringView message, QAnyStringView fileName, int lineNumber)
|
||||
{
|
||||
const QString lineString = lineNumber ? QString::number(lineNumber) : QString();
|
||||
return (base.noquote().nospace()
|
||||
<< message << ": " << fileName << ":" << lineString << ":").space();
|
||||
}
|
||||
|
||||
QDebug warning(QAnyStringView fileName, int lineNumber)
|
||||
{
|
||||
return message(qWarning(), "Warning", fileName, lineNumber);
|
||||
}
|
||||
|
||||
QDebug warning(const QCborMap &classDef)
|
||||
{
|
||||
// TODO: Once we have line numbers, use them
|
||||
const QAnyStringView file = QAnyStringViewUtils::toStringView(
|
||||
classDef, Constants::MetatypesDotJson::S_INPUT_FILE);
|
||||
if (!file.isEmpty())
|
||||
return warning(file);
|
||||
|
||||
const QAnyStringView name = QAnyStringViewUtils::toStringView(
|
||||
classDef, Constants::MetatypesDotJson::S_QUALIFIED_CLASS_NAME);
|
||||
return warning(name);
|
||||
}
|
||||
|
||||
QDebug error(QAnyStringView fileName, int lineNumber)
|
||||
{
|
||||
return message(qCritical(), "Error", fileName, lineNumber);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
@ -21,6 +21,11 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
QTypeRevision handleInMinorVersion(QTypeRevision revision, int majorVersion);
|
||||
|
||||
QDebug warning(const QCborMap &classDef);
|
||||
QDebug warning(QAnyStringView fileName, int lineNumber = 0);
|
||||
|
||||
QDebug error(QAnyStringView fileName, int lineNumber = 0);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QQMLTYPEREGISTRAR_UTILS_P_H
|
||||
|
|
|
@ -60,15 +60,17 @@ QCborMap FoundType::select(const QCborMap &category, QAnyStringView relation) co
|
|||
{
|
||||
if (toStringView(category, S_INPUT_FILE).isEmpty()) {
|
||||
if (javaScript.isEmpty()) {
|
||||
qWarning() << relation << "type of" << toStringView(category, S_QUALIFIED_CLASS_NAME)
|
||||
<< "is not a JavaScript type";
|
||||
warning(category)
|
||||
<< relation << "type of" << toStringView(category, S_QUALIFIED_CLASS_NAME)
|
||||
<< "is not a JavaScript type";
|
||||
}
|
||||
return javaScript;
|
||||
}
|
||||
|
||||
if (native.isEmpty()) {
|
||||
qWarning() << relation << "of" << toStringView(category, S_QUALIFIED_CLASS_NAME)
|
||||
<< "is not a native type";
|
||||
warning(category)
|
||||
<< relation << "of" << toStringView(category, S_QUALIFIED_CLASS_NAME)
|
||||
<< "is not a native type";
|
||||
}
|
||||
return native;
|
||||
}
|
||||
|
@ -92,8 +94,8 @@ FoundType QmlTypesClassDescription::findType(
|
|||
? FoundType::OwnTypes
|
||||
: FoundType::ForeignTypes;
|
||||
} else {
|
||||
qWarning() << "Multiple JavaScript types called"
|
||||
<< qualifiedName << "found!";
|
||||
warning(result.javaScript)
|
||||
<< "Multiple JavaScript types called" << qualifiedName << "found!";
|
||||
}
|
||||
} else if (result.native.isEmpty()) {
|
||||
result.native = *it;
|
||||
|
@ -101,8 +103,9 @@ FoundType QmlTypesClassDescription::findType(
|
|||
? FoundType::OwnTypes
|
||||
: FoundType::ForeignTypes;
|
||||
} else {
|
||||
qWarning() << "Multiple C++ types called" << qualifiedName << "found!"
|
||||
<< "This violates the One Definition Rule!";
|
||||
warning(result.native)
|
||||
<< "Multiple C++ types called" << qualifiedName << "found!"
|
||||
<< "This violates the One Definition Rule!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -421,8 +424,9 @@ void QmlTypesClassDescription::collect(
|
|||
// the "Invisible" test case. In that case, we must not assume anything about
|
||||
// access semantics.
|
||||
|
||||
qWarning() << "Warning: Refusing to generate non-lowercase name"
|
||||
<< elementName->toString() << "for unknown foreign type";
|
||||
warning(classDef)
|
||||
<< "Refusing to generate non-lowercase name"
|
||||
<< *elementName << "for unknown foreign type";
|
||||
elementName = elementNames.erase(elementName);
|
||||
|
||||
if (elementNames.isEmpty()) {
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
// Copyright (C) 2019 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "qqmltypescreator_p.h"
|
||||
#include "qqmltypesclassdescription_p.h"
|
||||
#include "qqmltyperegistrarconstants_p.h"
|
||||
#include "qanystringviewutils_p.h"
|
||||
#include "qqmltyperegistrarconstants_p.h"
|
||||
#include "qqmltyperegistrarutils_p.h"
|
||||
#include "qqmltypesclassdescription_p.h"
|
||||
#include "qqmltypescreator_p.h"
|
||||
|
||||
#include <QtCore/qset.h>
|
||||
#include <QtCore/qcborarray.h>
|
||||
|
@ -61,13 +62,15 @@ void QmlTypesCreator::writeClassProperties(const QmlTypesClassDescription &colle
|
|||
m_qml.writeStringBinding(S_EXTENSION, collector.javaScriptExtensionType);
|
||||
m_qml.writeBooleanBinding(S_EXTENSION_IS_JAVA_SCRIPT, true);
|
||||
} else {
|
||||
qWarning() << "JavaScript extension type for" << collector.className
|
||||
<< "does not exist";
|
||||
warning(collector.file)
|
||||
<< "JavaScript extension type for" << collector.className
|
||||
<< "does not exist";
|
||||
}
|
||||
|
||||
if (collector.extensionIsNamespace) {
|
||||
qWarning() << "Extension type for" << collector.className
|
||||
<< "cannot be both a JavaScript type and a namespace";
|
||||
warning(collector.file)
|
||||
<< "Extension type for" << collector.className
|
||||
<< "cannot be both a JavaScript type and a namespace";
|
||||
if (!collector.nativeExtensionType.isEmpty()) {
|
||||
m_qml.writeStringBinding(S_EXTENSION, collector.nativeExtensionType);
|
||||
m_qml.writeBooleanBinding(S_EXTENSION_IS_NAMESPACE, true);
|
||||
|
@ -78,7 +81,8 @@ void QmlTypesCreator::writeClassProperties(const QmlTypesClassDescription &colle
|
|||
if (collector.extensionIsNamespace)
|
||||
m_qml.writeBooleanBinding(S_EXTENSION_IS_NAMESPACE, true);
|
||||
} else if (collector.extensionIsNamespace) {
|
||||
qWarning() << "Extension namespace for" << collector.className << "does not exist";
|
||||
warning(collector.file)
|
||||
<< "Extension namespace for" << collector.className << "does not exist";
|
||||
m_qml.writeBooleanBinding(S_EXTENSION_IS_NAMESPACE, true);
|
||||
}
|
||||
|
||||
|
@ -95,10 +99,11 @@ void QmlTypesCreator::writeClassProperties(const QmlTypesClassDescription &colle
|
|||
return;
|
||||
|
||||
if (!collector.sequenceValueType.isEmpty()) {
|
||||
qWarning() << "Ignoring names of sequential container:";
|
||||
warning(collector.file) << "Ignoring names of sequential container:";
|
||||
for (const QAnyStringView &name : std::as_const(collector.elementNames))
|
||||
qWarning() << " - " << name.toString();
|
||||
qWarning() << "Sequential containers are anonymous. Use QML_ANONYMOUS to register them.";
|
||||
warning(collector.file) << " - " << name.toString();
|
||||
warning(collector.file)
|
||||
<< "Sequential containers are anonymous. Use QML_ANONYMOUS to register them.";
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -145,9 +145,9 @@ void tst_qmltyperegistrar::metaTypesRegistered()
|
|||
|
||||
auto verifyMetaType = [](const char *name, const char *className) {
|
||||
const auto foundMetaType = QMetaType::fromName(name);
|
||||
QVERIFY(foundMetaType.isValid());
|
||||
QVERIFY2(foundMetaType.isValid(), name);
|
||||
QCOMPARE(foundMetaType.name(), name);
|
||||
QVERIFY(foundMetaType.metaObject());
|
||||
QVERIFY2(foundMetaType.metaObject(), name);
|
||||
QCOMPARE(foundMetaType.metaObject()->className(), className);
|
||||
};
|
||||
|
||||
|
@ -408,19 +408,20 @@ void tst_qmltyperegistrar::duplicateExportWarnings()
|
|||
QVector<QCborMap> typesforeign = processor.foreignTypes();
|
||||
r.setTypes(types, typesforeign);
|
||||
|
||||
auto expectWarning = [](QString message) {
|
||||
QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
|
||||
const auto expectWarning = [](const char *message) {
|
||||
QTest::ignoreMessage(QtWarningMsg, message);
|
||||
};
|
||||
expectWarning("Warning: ExportedQmlElement was registered multiple times by following Cpp "
|
||||
"classes: ExportedQmlElement, ExportedQmlElement2 (added in 1.2), "
|
||||
"ExportedQmlElementDifferentVersion (added in 1.0) (removed in 1.7)");
|
||||
expectWarning("Warning: SameNameSameExport was registered multiple times by following Cpp "
|
||||
"classes: SameNameSameExport, SameNameSameExport2 (added in 1.2), "
|
||||
"SameNameSameExportDifferentVersion (added in 1.0)");
|
||||
expectWarning("Warning: duplicatedExports.h:: ExportedQmlElement is registered multiple times "
|
||||
"by the following C++ classes: ExportedQmlElement, ExportedQmlElement2 "
|
||||
"(added in 1.2), ExportedQmlElementDifferentVersion (added in 1.0) "
|
||||
"(removed in 1.7)");
|
||||
expectWarning("Warning: duplicatedExports.h:: SameNameSameExport is registered multiple times "
|
||||
"by the following C++ classes: SameNameSameExport, SameNameSameExport2 "
|
||||
"(added in 1.2), SameNameSameExportDifferentVersion (added in 1.0)");
|
||||
|
||||
QString outputData;
|
||||
QTextStream output(&outputData, QIODeviceBase::ReadWrite);
|
||||
r.write(output);
|
||||
r.write(output, "tst_qmltyperegistrar_qmltyperegistrations.cpp");
|
||||
}
|
||||
|
||||
void tst_qmltyperegistrar::clonedSignal()
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <cstdlib>
|
||||
|
||||
#include <QtQmlTypeRegistrar/private/qqmltyperegistrar_p.h>
|
||||
#include <QtQmlTypeRegistrar/private/qqmltyperegistrarutils_p.h>
|
||||
|
||||
using namespace Qt::Literals;
|
||||
|
||||
|
@ -120,7 +121,7 @@ int main(int argc, char **argv)
|
|||
|
||||
if (parser.isSet(extract)) {
|
||||
if (!parser.isSet(outputOption)) {
|
||||
fprintf(stderr, "Error: The output file name must be provided\n");
|
||||
error(module) << "The output file name must be provided";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
QString baseName = parser.value(outputOption);
|
||||
|
@ -145,16 +146,15 @@ int main(int argc, char **argv)
|
|||
QString outputName = parser.value(outputOption);
|
||||
QFile file(outputName);
|
||||
if (!file.open(QIODeviceBase::WriteOnly)) {
|
||||
fprintf(stderr, "Error: Cannot open \"%s\" for writing: %s\n",
|
||||
qPrintable(QDir::toNativeSeparators(outputName)),
|
||||
qPrintable(file.errorString()));
|
||||
error(QDir::toNativeSeparators(outputName))
|
||||
<< "Cannot open file for writing:" << file.errorString();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
QTextStream output(&file);
|
||||
typeRegistrar.write(output);
|
||||
typeRegistrar.write(output, outputName);
|
||||
} else {
|
||||
QTextStream output(stdout);
|
||||
typeRegistrar.write(output);
|
||||
typeRegistrar.write(output, "stdout");
|
||||
}
|
||||
|
||||
if (!parser.isSet(pluginTypesOption))
|
||||
|
@ -163,7 +163,7 @@ int main(int argc, char **argv)
|
|||
typeRegistrar.setReferencedTypes(processor.referencedTypes());
|
||||
const QString qmltypes = parser.value(pluginTypesOption);
|
||||
if (!typeRegistrar.generatePluginTypes(qmltypes)) {
|
||||
fprintf(stderr, "Error: Cannot generate qmltypes file %s\n", qPrintable(qmltypes));
|
||||
error(qmltypes) << "Cannot generate qmltypes file";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
|
|
Loading…
Reference in New Issue