Clarify error message for QML type registration

Fixes: QTBUG-114966
Change-Id: I3451cf38841cbefe0fa8d7c07ce91da372f8d184
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Amanda Hamblin-Trué 2023-06-29 17:05:30 +02:00
parent b9bfdea0e2
commit 6ea6bbeb32
3 changed files with 11 additions and 8 deletions

View File

@ -151,9 +151,10 @@ void QQmlPrivate::qmlRegistrationWarning(
{ {
switch (warning) { switch (warning) {
case UnconstructibleType: case UnconstructibleType:
qWarning() qWarning().nospace()
<< metaType.name() << metaType.name()
<< "is neither a QObject, nor default- and copy-constructible, nor uncreatable." << " is neither a default constructible QObject, nor a default- "
<< "and copy-constructible Q_GADGET, nor marked as uncreatable.\n"
<< "You should not use it as a QML type."; << "You should not use it as a QML type.";
break; break;
case UnconstructibleSingleton: case UnconstructibleSingleton:

View File

@ -826,8 +826,8 @@ struct QmlTypeAndRevisionsRegistration<T, Resolved, Extended, false, false, fals
} }
#else #else
static_assert(QQmlPrivate::QmlMetaType<Resolved>::hasAcceptableCtors(), static_assert(QQmlPrivate::QmlMetaType<Resolved>::hasAcceptableCtors(),
"This type is neither a QObject, nor default- and copy-constructible, nor" "This type is neither a default constructible QObject, nor a default- "
"uncreatable.\n" "and copy-constructible Q_GADGET, nor marked as uncreatable.\n"
"You should not use it as a QML type."); "You should not use it as a QML type.");
static_assert(std::is_base_of_v<QObject, Resolved> static_assert(std::is_base_of_v<QObject, Resolved>
|| !QQmlTypeInfo<Resolved>::hasAttachedProperties); || !QQmlTypeInfo<Resolved>::hasAttachedProperties);

View File

@ -536,13 +536,15 @@ void tst_qmltyperegistrar::uncreatable()
#if QT_DEPRECATED_SINCE(6, 4) #if QT_DEPRECATED_SINCE(6, 4)
QTest::ignoreMessage( QTest::ignoreMessage(
QtWarningMsg, QtWarningMsg,
"BadUncreatable is neither a QObject, nor default- and copy-constructible, " "BadUncreatable is neither a default constructible QObject, nor a default- "
"nor uncreatable. You should not use it as a QML type."); "and copy-constructible Q_GADGET, nor marked as uncreatable.\n"
"You should not use it as a QML type.");
qmlRegisterTypesAndRevisions<BadUncreatable>("A", 1); qmlRegisterTypesAndRevisions<BadUncreatable>("A", 1);
QTest::ignoreMessage( QTest::ignoreMessage(
QtWarningMsg, QtWarningMsg,
"BadUncreatableExtended is neither a QObject, nor default- and copy-constructible, " "BadUncreatableExtended is neither a default constructible QObject, nor a default- "
"nor uncreatable. You should not use it as a QML type."); "and copy-constructible Q_GADGET, nor marked as uncreatable.\n"
"You should not use it as a QML type.");
qmlRegisterTypesAndRevisions<BadUncreatableExtended>("A", 1); qmlRegisterTypesAndRevisions<BadUncreatableExtended>("A", 1);
#endif #endif