Accessing C++ Element exposed for QML in C++



  • I want to create a new component which can be exposed to QML.
    I figured out that the following lines would do the job:

    main.cpp
    @
    int main(int argc, char **argv) {
    ...
    Access access;
    ctxt->setContextProperty("access", &access);
    qmlRegisterType<TrayPaint>("TrayPaint", 1, 0, "TrayPaint");
    ...
    }
    @

    As shown above there is an object "access" which is also exposed to QML.
    How can I implement that the object "access" can change properties or call functions of the instance of object "TrayPaint" used in QML?

    I thought on something like the objectName-Property in QML. But I'm not shure.

    The TrayPaint object should display a (dynamic) number of circles. Each circles gets a number and a color property. The color should be changeable from C++.

    I started with this "tutorial":http://developer.qt.nokia.com/doc/qt-4.8/declarative-tutorials-extending-chapter1-basics.html


  • Moderators

    To expose a method from a C++ class to QML, you can use the "Q_INVOKABLE":http://developer.qt.nokia.com/doc/qt-4.8/qobject.html#Q_INVOKABLE macro.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.