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. Question on QDeclarativeItem attribute/properties
QtWS25 Last Chance

Question on QDeclarativeItem attribute/properties

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 3 Posters 5.3k Views
  • 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.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    See this code snip,

    @
    Text {
    id: text2
    text: qsTr("Hello devnet")
    }
    @

    If I now try to obtain the properties of this via this code:

    @
    QDeclarativeItem childitem = qobject_cast<QDeclarativeItem>(myobject);
    const QMetaObject *metaObject = childitem->metaObject();
    for(int j = 0; j < metaObject->propertyCount(); ++j)
    @

    and in the loop if I display all the properties, I find 2 issues that I'm seeking an answer to ...

    1. How can I get the id, "text2"
    2. The property "text" just shows "Hello devnet", how can I know if qsTr was used or not
    1 Reply Last reply
    0
    • K Offline
      K Offline
      kamalakshantv
      wrote on last edited by
      #2

      My understanding is that in QML the id and objectName are separate and in your case you might be able to access it via objectName.

      You can explicitly give an objectName like this

      @Text {
      id: text2
      objectName: "objText2"
      }@

      1 Reply Last reply
      0
      • B Offline
        B Offline
        baysmith
        wrote on last edited by
        #3

        Any property can be bound to arbitrary JavaScript. Are you asking to get the binding data or perhaps the source code for the binding?

        Nokia Certified Qt Specialist.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          [quote author="chetankjain" date="1292173184"]1. How can I get the id, "text2"[/quote]

          The id is not currently accessible from C++ (it is not an actual property in the meta object system). As QtK pointed out, you can use objectName, though generally it is discouraged to work with the internals of a QML app from C++ in this way (see the warning "here":http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#locating-child-objects)

          [quote author="chetankjain" date="1292173184"]2. The property "text" just shows "Hello devnet", how can I know if qsTr was used or not[/quote]

          This is also not currently possible to get from the meta object system (which only gives access to the value of the property), unless the property is of type "QDeclarativeScriptString":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativescriptstring.html.

          Can you say any more about what you would like to use these two pieces of information for? Note that the (private) QML debug/dom API allows access to both of these things for Creator.

          Regards,
          Michael

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

            [quote author="QtK" date="1292175104"]My understanding is that in QML the id and objectName are separate and in your case you might be able to access it via objectName.
            [/quote]
            No I do not want to use the objectName, I will explain my scenario below ...

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on last edited by
              #6

              [quote author="mbrasser" date="1292200382"]though generally it is discouraged to work with the internals of a QML app from C++ in this way (see the warning "here":http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html#locating-child-objects)
              ...

              This is also not currently possible to get from the meta object system (which only gives access to the value of the property), unless the property is of type "QDeclarativeScriptString":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativescriptstring.html.

              Can you say any more about what you would like to use these two pieces of information for? Note that the (private) QML debug/dom API allows access to both of these things for Creator.
              [/quote]

              I'm writing a test application to do some specific tests/checks on a QML based application and wanted this info from the QML object tree/composition .. my access is read only and will never modify the QML.

              Thanks for the links. :)
              I will chk further and revert ...

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mbrasser
                wrote on last edited by
                #7

                [quote author="chetankjain" date="1292307467"]I'm writing a test application to do some specific tests/checks on a QML based application and wanted this info from the QML object tree/composition .. my access is read only and will never modify the QML.[/quote]

                For reference, here is an earlier discussion on the mailing list regarding testing/id access:
                http://lists.trolltech.com/pipermail/qt-qml/2010-November/001532.html

                Regards,
                Michael

                1 Reply Last reply
                0
                • ? This user is from outside of this forum
                  ? This user is from outside of this forum
                  Guest
                  wrote on last edited by
                  #8

                  thanks Micheal, this is very helpful, :)
                  I'll explore qmlunit next, probably relook at my approach

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mbrasser
                    wrote on last edited by
                    #9

                    One more link of interest in regards to testing QML:
                    http://bugreports.qt.nokia.com/browse/QTBUG-15801 (QML testing requirements)

                    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