Important: Please read the Qt Code of Conduct -

Loop or linear traverse to fill qml-objects

  • Hi,

    I am new to Qt and Qml, but I am very excited after experiencing the power of these toolkit. I have one question regarding QML. From what I understand, there is nothing like a loop or iterator in QML , and we have to rely on JavaScript or C++(my preferred lang.) to do that work.

    Say I have a text file with each line mentioning dimension of different rectangles, and their colors that i need to draw in certain fashion on the screen. I am able to load these details into some C++ structure object, and now I am trying to draw them using grid, or simply in linear fashion. How can I keep reading details of next rectangle from Qml, and then stop when the last rectangle is read? Is signal/slot helpful in doing so?

    Please guide me. Any link to sample code example will be helpful in this regards.


  • i am very new to Qt and QML as well.
    But this sound to me as your text file could be the model of a component using a delegate to draw one rectangle.
    if you are not already familiar with the model/delegate concept you could check the docu.
    maybe this helps

  • Thanks Stefan. I will have a look into this.

Log in to reply