Getting QML Object data to a class in C++



  • Hello Qt community,

    I've been searching and testing some new QML functionalities and I am in doubt.

    What I would like to do is to get the information of an object in QML to a class in C++.

    Right now I've beel able to extend the QML functionality by creating a class that inherits from QDeclarativeView, and in this class I have some data members and its respective Q_PROPERTY getters and setters to be used in the QML.

    So lets say in my QML I have something like this:

    myClassExtensionObject{
    name: "QML Object name goes here"
    }

    And as my C++ class I have something like:

    @class myClassExtensionObject{

    Q_PROPERTIES( name READ getterFunction WRITE setterFunction )
    void setterFunction() const;
    Qstring getterFucntion();

    private:
    QString name;
    }@.... and so on.

    So this works perfeclty....as I understand, and object instance of myClassExtensionObject is created in the QML.... but what I would like to do is to get this QML object (instance) and use its information in some other class in C++ to process and freely handle this information from the QML.

    I am not sure how to achieve such a thing, and hopefully I am explaining myself correctly.

    Thanks in advace Qt Community.

    Regards


  • Moderators

    Take the rootObject from QML engine, then use findChildren() method to look for kids. You can modify the object with meta-object controls (setProperty(), property(), invokeMethod()). Just remember that you need to name your QML object using objectName property. id set in QML is invisible to c++.


Log in to reply
 

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