Details
-
Bug
-
Resolution: Out of scope
-
P4: Low
-
None
-
5.2.0
-
None
Description
class QQuickAbstractMessageDialog : public QQuickAbstractDialog { Q_OBJECT Q_ENUMS(Icon) Q_PROPERTY(Icon icon READ icon WRITE setIcon NOTIFY iconChanged) public: enum Icon { NoIcon, Information, Warning, Question }; ... } class QQuickQMessageBox : public QQuickAbstractMessageDialog ... implementation using QMessageBox ... qmlRegisterType<QQuickQMessageBox>(uri, 1, 1, "QtMessageDialog");
WidgetMessageDialog.qml:
import QtQuick 2.1 import QtQuick.PrivateWidgets 1.1 QtMessageDialog { }
qmlRegisterType("file:///path/to/WidgetMessageDialog.qml", "QtQuick.Dialogs", 1, 1, "MessageDialog");
Now finally the test QML:
MessageDialog { icon: MessageDialog.Warning }
MessageDialogs.qml:59:15: Unable to assign [undefined] to int
The reason is that MessageDialog is a "composite type". Even though it's based on a C++ class, the Q_ENUMS from the C++ class are not inherited inside MessageDialog. I can work around it by registering the abstract C++ type too:
qmlRegisterType<QQuickAbstractMessageDialog>(..., "AbstractMessageDialog")
then AbstractMessageDialog.Warning will exist and can be used in QML. But this breaks encapsulation so is not as nice as MessageDialog.Warning.
I can't use an alias either, but maybe we need a similar concept to be able to alias an enum in a QML type; or else inherit all the enums automatically so I don't have to do that.
As an alternative workaround I might have to register the enums in the QtQuick.Dialogs namespace or something like that (the way that Qt.xxx is a catchall for a lot of enums).