Important: Please read the Qt Code of Conduct -

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:

    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 Extras

    Item {
    Extras.Action { ... }


Log in to reply