Home > Mobile >  How to write a for loop in qml?
How to write a for loop in qml?

Time:02-20

I am trying to add tick marks for dial on qml. I made the calculations and created the tick marks manually but want them to appear automatically based on the step size of the dial. My idea is to use a for loop but I don't know how to call the javascript in qml. Is the for loop the way to go and how does the code look like? Or do you have a better, more qml-like solution?

for i = (0,n):
  gamma = alpha i*delta
  mix = sin (gamma) * (a r l/2)
  miy = cos (gamma) * (a r l/2)
  create tick mark i with mix, miy, gamma, l
end for

This is the logic that I want to put in the loop.

CodePudding user response:

I think you can just do it like this:

for (var i = 0; i < 10; i  ) {

}

CodePudding user response:

You should write your for loop inside a function like below:

function doing_in_loop() {
  for (var i = 0; i < 9; i  )  {
      console.log(i)
  }
}

or do in on a signal:

Component.onCompleted: {
   for (var i = 0; i < 9; i  )  {
      console.log(i)
   }
}
  • Related