Sanath
Sanath

Reputation: 11

How to write a for loop in qml?

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.

Upvotes: 1

Views: 5594

Answers (2)

Farshid616
Farshid616

Reputation: 1484

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)
   }
}

Upvotes: 1

Ryan Glenn
Ryan Glenn

Reputation: 1416

I think you can just do it like this:

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

}

Upvotes: 0

Related Questions