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. Dynamic object's id in QML
Forum Updated to NodeBB v4.3 + New Features

Dynamic object's id in QML

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 7.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.
  • N Offline
    N Offline
    nocknock
    wrote on last edited by
    #1

    i am generating new QML object with the following code:
    The polygon object is a type that i define with C++:

    @var newObject = Qt.createQmlObject("import MyTypes 1.0;"+
    "import QtQuick 1.0;"+
    "import Qt 4.7;"+
    "Polygon {"+
    "id:_"+polygonID+";"+
    //"anchors.fill:parent;"+
    "x:645; y:0;"+
    //"width: 0; height: 0;"+
    "color: "+polygonColor+";"+
    //"scale:0.3;"+
    "vertices:["+
    polygonPointsString+
    "]"+
    "Component.onCompleted:{ container.pntx= _"+polygonID+".leftAndTopOfBoundingRect().x;"+
    "container.pnty= _"+polygonID+".leftAndTopOfBoundingRect().y;"+
    "}"+
    "}",
    parentObj, "dynamicSnippet3");

    console.log"id:"+(newObject.id);
    @

    after
    @ console.log"id:"+(newObject.id);@
    line it writes:

    id:undefined

    but if i write
    @ console.log"id:"+(newObject.x);@
    line it writes:

    645 the true answer

    where am i wrong, why id is undefined?

    thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Diph
      wrote on last edited by
      #2

      http://developer.qt.nokia.com/doc/qt-4.7/qdeclarativedynamicobjects.html#id-fc2906d7-a32a-4875-a420-59d951346a29

      Also, note that while dynamically created objects may be used the same as other objects, they do not have an id in QML.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nocknock
        wrote on last edited by
        #3

        thanks, i have looked at that page but did not see that line.
        if so how can i access to that objects?
        @Scale {
        id: scaleItem
        origin.x: 0; origin.y: 0; xScale: 1.2; yScale:1.2
        }@
        i must access this element,and assign it to "transform" variable of my component and i think i can do it using id, if there is no id, how?
        thanks very much for the reply

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

          You use variable of that dynamically created element (newObject.transform ).

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nocknock
            wrote on last edited by
            #5

            thanks,
            i can not try it at the moment but i need to write

            @newObject.trasnform=scaleItem;//scale item id@

            i can not do it because i will generate scale item dynamically too.

            thus can i write

            @newScaleObject=createQMLObject("import Qt 4.7; Scale{origin.x:0; blah blah}");@

            and can i write:

            @
            newObject.transform:newScaleObject@

            ?
            is it possible?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Diph
              wrote on last edited by
              #6

              @var newScaleObject=createQMLObject("import Qt 4.7; Scale{origin.x:0; blah blah}");
              newScaleObject.transform = scaleItem@

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nocknock
                wrote on last edited by
                #7

                @Diph, "scaleItem" is an id of dynamically generated object.
                thus i can not use it, system does not allow,
                anyway i will try something; hope i can succeed,

                thanks for your time @Diph and @minimoog77

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Diph
                  wrote on last edited by
                  #8

                  Sorry, I didn't notice the content of the createQMLObject. Your code should work if you change the second line to newObject.transform = newScaleObject

                  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