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. Dynamic Qt.createQmlObject with ID
Forum Updated to NodeBB v4.3 + New Features

Dynamic Qt.createQmlObject with ID

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.5k Views 2 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.
  • H Offline
    H Offline
    Hergo
    wrote on 28 Jul 2015, 11:44 last edited by Hergo
    #1

    Hi,
    As you can see below I'm trying to communicate between two : Qt.createQmlObject

    In the 1st I create a "Rectangle" and in the second I create the "Text".
    I want the second, that anchored with the rectangl : Anchors.centerIn

    But it seems he does not see the ID of "Rectangle". Error : Error: Qt.createQmlObject(): failed to create object:
    If I erase << anchors.centerIn: "menuId_'+menu[i].id+' " >>, all work fine but the text is on same place.

    Where did I make a mistake?

     Component.onCompleted:
             {
                    var x=0;
                    var y=0;
                    var titi_debug=0;
                    var menu = JSON.parse(getData('object'));
                    for(var i = 0; i < menu.length; i++)
                    {
                        console.log("JSON Parse: " + menu[i].id);
                        console.log("JSON Parse: " + menu[i].name);
    
                        Qt.createQmlObject('import QtQuick 2.0;
                                                            Rectangle {id : "menuId_'+menu[i].id+'"; color: "red"; width: 50; height: 50; x: '+x+'; y:'+y+'}', tuile, "toto");
                        Qt.createQmlObject('import QtQuick 2.0;
                                                            Text {id : "textId_'+menu[i].id+'"; text: "'+menu[i].name+'"; color: "white"; anchors.centerIn: "menuId_'+menu[i].id+'"}', tuile, "tata");
                        y=y+100;
                        titi_debug=x+100;
                    }
    
    
                }
    
    P 1 Reply Last reply 28 Jul 2015, 16:15
    0
    • H Hergo
      28 Jul 2015, 11:44

      Hi,
      As you can see below I'm trying to communicate between two : Qt.createQmlObject

      In the 1st I create a "Rectangle" and in the second I create the "Text".
      I want the second, that anchored with the rectangl : Anchors.centerIn

      But it seems he does not see the ID of "Rectangle". Error : Error: Qt.createQmlObject(): failed to create object:
      If I erase << anchors.centerIn: "menuId_'+menu[i].id+' " >>, all work fine but the text is on same place.

      Where did I make a mistake?

       Component.onCompleted:
               {
                      var x=0;
                      var y=0;
                      var titi_debug=0;
                      var menu = JSON.parse(getData('object'));
                      for(var i = 0; i < menu.length; i++)
                      {
                          console.log("JSON Parse: " + menu[i].id);
                          console.log("JSON Parse: " + menu[i].name);
      
                          Qt.createQmlObject('import QtQuick 2.0;
                                                              Rectangle {id : "menuId_'+menu[i].id+'"; color: "red"; width: 50; height: 50; x: '+x+'; y:'+y+'}', tuile, "toto");
                          Qt.createQmlObject('import QtQuick 2.0;
                                                              Text {id : "textId_'+menu[i].id+'"; text: "'+menu[i].name+'"; color: "white"; anchors.centerIn: "menuId_'+menu[i].id+'"}', tuile, "tata");
                          y=y+100;
                          titi_debug=x+100;
                      }
      
      
                  }
      
      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 28 Jul 2015, 16:15 last edited by
      #2

      @Hergo id doesnot work in this case. See more info here.

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

      157

      1 Reply Last reply
      0

      1/2

      28 Jul 2015, 11:44

      • Login

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