Details
-
Suggestion
-
Resolution: Done
-
P2: Important
-
5.4.0
-
None
-
8e7d1a91196197eee4e45bbfa9886ab935e2b67c
Description
A common problem for controls is that when the business logic is implemented in a C++ "base" type and the visual parts in a QML "sub" type, attached properties provided by the C++ type (hidden implementation detail) cannot be accessed by the public QML type name.
Example: a generic ScrollIndicator that can be attached to any Flickable.
C++ base type:
// qquickabstractscrollindicator_p.h class QQuickScrollIndicatorAttached : public QObject { Q_OBJECT Q_PROPERTY(QQuickAbstractScrollIndicator *horizontal ...) Q_PROPERTY(QQuickAbstractScrollIndicator *vertical ...) }; class QQuickAbstractScrollIndicator : public QQuickItem { Q_OBJECT public: explicit QQuickAbstractScrollIndicator(QQuickItem *parent = Q_NULLPTR); static QQuickScrollIndicatorAttached *qmlAttachedProperties(QObject *object); }; QML_DECLARE_TYPEINFO(QQuickAbstractScrollIndicator, QML_HAS_ATTACHED_PROPERTIES) // qtquickcontrolsplugin.cpp qmlRegisterType<QQuickAbstractScrollIndicator>(uri, 2, 0, "AbstractScrollIndicator");
QML type:
// qmldir ScrollIndicator 2.0 ScrollIndicator.qml // ScrollIndicator.qml AbstractScrollIndicator { id: control implicitWidth: ... implicitHeight: ... indicator: Rectangle { ... } background: Rectangle { ... } }
Application code cannot use ScrollIndicator.vertical (QML engine throws "Non-existent attached object" error), but the attached property must be referenced using the C++ base type name ie. AbstractScrollIndicator. This makes naming very difficult to achieve optimal API for such controls.
Flickable { // ScrollIndicator.vertical: ScrollIndicator { ... } // "Non-existent attached object" // vs. AbstractScrollIndicator.vertical: ScrollIndicator { ... } // :( }
Attachments
Issue Links
- relates to
-
QTBUG-43582 Enums declared in C++ base type
-
- Closed
-