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 to assign id to dynamically created object
Forum Updated to NodeBB v4.3 + New Features

How to assign id to dynamically created object

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 4 Posters 5.5k 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.
  • F Offline
    F Offline
    franziss
    wrote on 21 Jun 2011, 02:58 last edited by
    #1

    Dear all,

    This question is originated from a previous post, which deviates from the main topic of the post.

    I have a button, which when pressed, will create an object. This object is actually a slide (if you think of it as a power point slide kind of thing), which I use qml rectangle to represent. So I am trying to give each slide an id, which is in this way: slide1, slide2, …. sliden

    I understand that we cannot dynamically assigned id to the dynamically created object.
    http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeintroduction.html
    This is super weird, if this is not possible, how are we able to reference our dynamically created object???

    But I realise that for GridView model, we can do this

    @
    GridView {
    model: TextIconModel {id:textIconModel} // declare the id of the object that you instantiated
    delegate: textIconDelegate
    }
    @

    So this is contradicting, are we able to assign id to dynamically created object?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thisisbhaskar
      wrote on 21 Jun 2011, 08:50 last edited by
      #2

      The above example you have given is bit different. You are assigning a concrete TextIconModel to model which is just fine.

      I agree with you saying that there should be a way to give id to dynamically created objects. I added my rating to this :)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sigrid
        wrote on 21 Jun 2011, 10:10 last edited by
        #3

        What you can do is to create a property variant variable and then assign the javascript object to that variable. Something like:

        @
        property variant foo;
        onSomethingHappened: {
        theObject = getMeTheObject();
        foo = theObject;
        }
        @

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thisisbhaskar
          wrote on 21 Jun 2011, 10:14 last edited by
          #4

          @sigrid, thanks for your reply. But did not get your answer. The question was is on how to assign id to a dynamically created object.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sigrid
            wrote on 21 Jun 2011, 10:37 last edited by
            #5

            It is not possible to assign an id to an object. The id is part of the parsing context of the .qml file and only available inside that .qml file. The id is not accessible through JS or C++. It is possible to reference an object via its ID from JavaScript, but that is an id->name mapping that the declarative engine handles. The ID is not accessible. Hence, the second best thing is a hack that lets you access a JS created object as if it had been named, through a member property, as suggested in my previous post. Note that this is as I mentioned, a hack.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              thisisbhaskar
              wrote on 21 Jun 2011, 10:41 last edited by
              #6

              ok.. thanks for you clarification. Got it now. Knowing that id is not considered as the property of the object, I know that we can not assign a value to id like other properties of the qml components. But it would be very nice if we can do it somehow in the future versions of QtQuick. I hope this is on your cards???

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on 21 Jun 2011, 10:42 last edited by
                #7

                [quote author="Vijay Bhaska Reddy" date="1308651284"]@sigrid, thanks for your reply. But did not get your answer. The question was is on how to assign id to a dynamically created object.[/quote]

                That is because you asked the wrong question. You asked how to assign an id. As you say yourself earlier on, that is not possible:
                [quote author="franziss" date="1308625139"]I understand that we cannot dynamically assigned id to the dynamically created object.[/quote]

                So, asking that, is obviously the wrong question. What you really wanted to know, is given that you can not use ids, what kind of mechanism you can use to refer to dynamically created objects. That is the question that sigrid answered for you.

                1 Reply Last reply
                0

                1/7

                21 Jun 2011, 02:58

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved