Details
-
Task
-
Resolution: Won't Do
-
P3: Somewhat important
-
None
Description
Qmltc does not emit any errors or warnings on qml files where the root component has required properties:
// TypeWithRequiredProperty.qml import QtQuick Item { required property int myProperty } // This file cannot be compiled with qmltc because the required property is missing // alwaysBadFile.qml import MyModule import QtQuick Item { TypeWithRequiredProperty { id: bad } } // This file can be compiled (but without neither warning nor error, while a QQmlComponent::create() would return nullptr if myProperty is still not set at runtime) // sometimesBadFile.qml import MyModule import QtQuick TypeWithRequiredProperty { id: sometimesBad }
Where
QQmlComponent::create()
would return an error during runtime if
QQmlComponent::setInitialProperties()
was not called with the QVariantMap nameOfRequiredProperties -> values,
the class generated by qmltc can be initialized with the default empty constructor
sometimesBadFile created();
and does not warn that a required property is missing (until much later when that property is used for something and just contains its default value).
Therefore, qmltc should stop generating the default empty constructors for types with required properties and instead generate a constructor like
sometimesBadFile::sometimesBadFile(int myProperty);
or
sometimesBadFile::sometimesBadFile(const QPropertyBinding<int>& myProperty);
when the property is bound to a value, such that setBinding() can be called on the required property.
Note 1: which of these overloads should be accepted? (see Qbindable::setBinding() overloads)
sometimesBadFile::sometimesBadFile(const QPropertyBinding<int>& myProperty); sometimesBadFile::sometimesBadFile(const QUntypedPropertyBinding& myProperty); template <typename Functor> sometimesBadFile::sometimesBadFile( Functor &&f, const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION, std::enable_if_t<std::is_invocable_v<Functor>> * = nullptr);
Note 2: once one overload is chosen, how should the combinatorial explosion be handled (e.g. for n required properties there are 2^n possible constructors if every property can be passed in as a constant value or as a binding for the bindable). Maybe using something like a
std::variant<QPropertyBinding<int>, int>
might help?
Attachments
Issue Links
- is required for
-
QTBUG-105898 Teach views/QQmlComponent how to use qmltc's generated classes
- Reported
-
QTBUG-105538 qmltc evolution collection task
- Open
For Gerrit Dashboard: QTBUG-105896 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
450420,4 | WIP: qmltc: require required properties in constructor | dev | qt/qtdeclarative | Status: ABANDONED | -2 | 0 |