Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to implement a QAction type in QML?
Forum Updated to NodeBB v4.3 + New Features

How to implement a QAction type in QML?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 3.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gault
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      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 Extras

      Item {
      Extras.Action { ... }
      }
      @

      Regards,
      Michael

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved