Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting QML Object data to a class in C++
Forum Updated to NodeBB v4.3 + New Features

Getting QML Object data to a class in C++

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.4k 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.
  • Q Offline
    Q Offline
    Qnoobish
    wrote on last edited by
    #1

    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

    In short, software is eating the world.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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++.

      (Z(:^

      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