How to implement a QAction type in QML?
-
As I known, QAction is supported in QML as a basic type. However, it could not be defined as a property in QML. Instead, QAction type must be defined in C++ and then used in QML.
I really want a way how to define an Action in QML, or implement one? It's really inconvenient if could not do this.
-
In qdeclarativeitemsmodule.cpp, QAction is registered as @qmlRegisterType<QAction>();@
This type of registration does not make the class available for instantion in QML as an element. There are (at least) two pieces missing:
- QAction doesn't have a default constructor (see requirement "here":http://doc.qt.nokia.com/4.7-snapshot/qml-extending.html#adding-types)
- registration would need to be done via qmlRegisterType<QAction>("Qt",4,7,"Action");
One option might be for you to subclass QAction, provide a default constructor, and then register the type yourself, in a QML plugin. e.g. @qmlRegisterType<QAction>("MyComponents",1,0,"Action");@
and then @import Qt 4.7
import MyComponents 1.0 as ExtrasItem {
Extras.Action { ... }
}
@Regards,
Michael