Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

284
Visualizações
How can I push 3 or 4 variables into the array list in QML at a time

I am new to qml and javascript technologies. I need sample example on push and pop operations on the array. For example, how can I push 3 variables into the array list in QML at a time. I want the output to be like below [{"A001", 1, "Item1"}, {"A002", 2, "Item2"}]. I have started with sample code but could not able to complete the logic in Component.onCompleted.

Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")

property var object: ({})
property var list: []

property string str1: "A001"
property int value1: 1
property string item1: "Item1"

property string str2: "A002"
property int value2: 2
property string item2: "Item2"

Component.onCompleted: {
    //1. Frame the object {str1, value1, item1}
    //2. Push to the array using push operation
    //3. The output of the array to be [{"A001", 1, "Item1"}]

    //4. Frame the object {str2, value2, item2}
    //5. Push to the array using push operation
    //6. The output of the array to be [{"A001", 1, "Item1"},{"A002", 2, "Item2"}]
    
    //7. Do pop operation on the array
    //8. The output of the array to be [{"A001", 1, "Item1"}]

    //9. Do pop operation on the array
    //10. The output of the array to be []
}

}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It looks like you want an array of objects. In javascript, objects are key/value pairs. So you have to create them something like this:

var obj1 = {"str": str1, "value": value1, "item": item1}
var obj2 = {"str": str2, "value": value2, "item": item2}

Then you can push or pop them onto your array:

var arr = [];
arr.push(obj1);
arr.push(obj2);
arr.pop();
arr.pop();
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda