Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How do I print the "id" attribute of Item?
Forum Updated to NodeBB v4.3 + New Features

How do I print the "id" attribute of Item?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 965 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.
  • M Offline
    M Offline
    Maksym
    wrote on last edited by
    #1

    Good day!

    How to print "id" attribute?

    I want to trace focus. Now I forced to use "objectName" property, but I want to print "id" directly.

    [code]
    Window {
    visible: true

    onActiveFocusItemChanged: {
        var fitem = activeFocusItem
        if (fitem)
            do
                console.log(fitem.objectName)
            while (fitem = fitem.parent)
        else
            console.log("no focus")
    }
    

    }
    [/code]

    How to print the "id" attribute?

    Best regards.

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

      Printing the item using its id (rather than the id property of the item) works. If the objectName property is defined, that will also be output. For example:

      @
      Item {
      id: myItem
      objectName: "my item"
      Component.onCompleted: print(myItem)
      }
      @

      should result in something along the lines of:
      qml: QQuickItem(0x101e12c60, "my item")

      edit: The same applies for properties or variables assigned the value of the item using its id

      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