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 load a Element dynamically into already dynamically loaded qml file.
Forum Updated to NodeBB v4.3 + New Features

How to load a Element dynamically into already dynamically loaded qml file.

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

    Hi All,

    I am loaded a qml file dynamically in the following manner.

    @function renew()
    {
    comp = Qt.createComponent("PushButtonAct.qml");
    // if(model.controltype.PushButton)
    console.log("model.controltype.PushButton",model.controltype);
    if(model.controltype==="PushButton"){
    if (comp.status === Component.Ready) {
    pushButton = comp.createObject(root, {"helpText" : model.pushButtonViewModel.helpText});

            if (pushButton === null) {
                console.log("Error creating object PushButtonAct");
            }
        } else if (comp.status === Component.Error) {
            console.log("Error loading component:", comp.errorString());
        }
    }
    

    }
    @

    depending on the condition if(model.controltype==="PushButton")
    i want to show a Element in the PushButtonAct.qml.

    how to do this.?

    Thanks in advance.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      @
      pushButton = comp.createObject(root, {"helpText" : model.pushButtonViewModel.helpText});
      @

      Is pushButton null after this ?

      157

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

        No it will be there .

        1 Reply Last reply
        0
        • B Offline
          B Offline
          basha92
          wrote on last edited by
          #4

          I want to load another Rectangle like element in the PushButtonAct.qml dynamically.

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            The approach is correct. Any other errors ?

            157

            1 Reply Last reply
            0
            • B Offline
              B Offline
              basha92
              wrote on last edited by
              #6

              Hi ,

              Actually I have a ToggleButton component in my folder and i want to call that one in PushButtonAct.qml and code is as folows

              @
              function renew()
              {
              comp = Qt.createComponent("PushButtonAct.qml");
              // if(model.controltype.PushButton)
              console.log("model.controltype.PushButton",model.controltype);
              if(model.controltype==="PushButton"){
              if (comp.status === Component.Ready) {
              pushButton = comp.createObject(root, {"helpText" : model.pushButtonViewModel.helpText});
              pushButton = comp.createObject(root, {"rectanglepopulate": ToggleButton});

                      if (pushButton === null) {
                          console.log("Error creating object PushButtonAct");
                      }
                  } else if (comp.status === Component.Error) {
                      console.log("Error loading component:", comp.errorString());
                  }
              }
              

              }
              @

              I am getting ReferenceError: Can't find variable: ToggleButton.

              In PushButtonAct.qml i have

              @
              Rectangle{
              id: root;
              property alias helpText : text1.text;
              property alias rectanglepopulate: rectanglepopula

              Rectangle {
              id:rectanglepopula
              x:40
              y:70
              width:75
              height:30
              }
              }
              @

              How to find the Reference of ToggleButton in .js file. ?

              1 Reply Last reply
              0
              • p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #7

                AFAIK, you will need to instantiate ToggleButton before using it in the JS. For eg:
                @
                property QtObject toggleButton: Qt.createComponent("ToggleButton.qml")
                @

                Then in JS you can get reference to toggleButton.

                157

                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