Results 1 to 2 of 2

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

  1. #1
    Join Date
    Feb 2012
    Location
    Germany
    Posts
    6
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question 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

    Qt Code:
    1. int main(int argc, char **argv) {
    2. ...
    3. Access access;
    4. ctxt->setContextProperty("access", &access);
    5. qmlRegisterType<TrayPaint>("TrayPaint", 1, 0, "TrayPaint");
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Accessing C++ Element exposed for QML in C++

    like you would do in c++ :
    access must know what instance of traypaint to interact with (a pointer).
    and have functions declared as Q_INVOKABLE so that they can be called from qml.
    from the qml side the instance pointer would be the id

  3. The following user says thank you to Le_B for this useful post:

    Rocken (15th March 2012)

Similar Threads

  1. Know Number of Property Exposed by the Widget
    By Ashutosh2k1 in forum Qt Programming
    Replies: 4
    Last Post: 29th June 2011, 13:12
  2. Qt types exposed as Variant in javascript
    By dioselin in forum Newbie
    Replies: 1
    Last Post: 15th April 2010, 18:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.