Skip to main content
tv9
Associate
June 10, 2025
Solved

How can I change the values for each child within a container?

  • June 10, 2025
  • 1 reply
  • 298 views

Hello,

 

I was wondering how can I change the values of each child within a container? For example, I have a container with 4 slider widgets. I want to be able to set the values of each slider using a for loop. Below shows a very simplified example of what I'm trying to achieve within Screen1View.cpp. I want to use array iteration instead of setting each slider value manually because I'll eventually have more than 10 sliders in the container.

 

Screen1View::Screen1View()
{

}
void Screen1View::setupScreen()
{
 int presets[4] = { 5, 10, 15, 20 };
 for (int i; i < 4; i++)
 {
 // in the container, each of the 4 slider widgets is being set to a preset value from an array
 containerSliders[i].setValue(presets[i]); 
 }
}

 

While looking into this more, I saw that containers have a forEachChild public function, but I am unsure how to use GenericCallback for this use case. If this is the way to go, can a simplified example be provided?

 

Thanks for the help in advance!

1 reply

GaetanGodart
GaetanGodartBest answer
Technical Moderator
June 11, 2025