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. How to get the qml object's id in the C++ class which defined for QML?
Forum Updated to NodeBB v4.3 + New Features

How to get the qml object's id in the C++ class which defined for QML?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 232 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.
  • S Offline
    S Offline
    Sauntor
    wrote on last edited by
    #1

    I write a qml type in C++(Demo for example):

    class Demo : public QObject
    {
    Q_OBJECT
    QML_ELEMENT
    Q_PROPERY(QString name ...)
    //...
    };
    

    and then, I use Demo in qml as the following:

    Demo {
    id: demo1
    name: "dddd"
    age: 3
    //.....
    }
    

    The question is:
    Is there a way to get the id (a.k. demo1) of Demo in the demo.cpp(i.e. in Demo::Demo())?

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      Is the goal a QObject *, or the string used in the id?

      The QObject * is this within the constructor.

      The string version is available via QQmlContext::nameForObject()

      Asking a question about code? http://eel.is/iso-c++/testcase/

      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