Registering an Enumeration through a Plugin
-
XmlListModel has the ability to access it's enumeration values for Status in QML (Qt Quick).
@
if (status == XmlListModel.Ready) {
// do something
}
@I would like my class to expose it's enumerated values as well. The following QML does not work:
@
if (status == MyModel.Ready) { // ERROR (ReferenceError: Can't find variable: MyModel)
// do something
}if (status == XmlListModel.Ready) { // SUCCESS (My enum values match XmlListModel's enums)
// do something
}if (status == 1) { // SUCCESS (Just making sure my plugin works and it isn't a red herring)
// do something
}
@I get the following error: ReferenceError: Can't find variable: MyModel.
MyModel.h
@
class MyModel : public QAbstractListModel
{
Q_Object
Q_PROPERTY(Status status READ getStatus NOTIFY statusChanged);public:
Q_ENUMS(Status)
enum Status { Null, Ready, Loading, Error };
Status getStatus() const;private:
Status _status;signals:
void statusChanged(MyModel::Status);...
}
@MyPlugin.cpp
@
void Plugin::registerTypes(const char *uri)
{
qmlRegisterType<MyModel>(uri, 1, 0, "MyModel");
}Q_EXPORT_PLUGIN2(MyPlugin, MyPugin)
@ -
Okay. This seems to work fine in the non-plugin case, and I suspect it would work correctly for plugins with an explicit import statement as well. Could you please add a bug report for this using the "tracker":http://bugreports.qt.nokia.com?
-
I have a problem similar to this topic except the use of the plugin.
I build an qml interface to share signals and information between my c++ and qml layer.
It works fine but I can't provide my enums to qml. I already saw an example to this topic but I miss some informations.
Could you show me an Example of how to providing an enum to qml ?
Thanks
-
Sorry for not updating till now. I was able to resolve this issue.
First, I had to change the registration function to:
@
void Plugin::registerTypes(const char *uri)
{
qmlRegisterType<MyModel>("MyPlugin", 1, 0, "MyModel");
}Q_EXPORT_PLUGIN2(MyPlugin, MyPugin)
@Then included:
@
import MyPlugin 1.0
@Without any additional changes, the Enumeration was visible to QML.