Set value to multiple Qlabels using 1 ComboBox
-
Hello, im trying to set the value from a combobox to multiple Qlabels, the idea is to populate the QcomboBox with all the values, then according to the number, (ejem 15.6) the corresponding label should change the problem is, theres too many of them to simply use a switch of something similar, but all the names of the labels are similar, HumSec_val156 corresponds to 15.6 the main idea was to use
Silo* silo = new Silo; QString number = widget.QComboBox->currentText(); QString nameOfLabel = "HumSec_val"; nameOfLabel.append(QString::number(number)); silo->findchild<QLabel*>(nameOfLabel)->setText(valuefromCombobox);
but everytime it simply return an empty string, i did try using somthing simplier like
widget.nameOfLabel->setText(valuefromComboBox);
but nameOfLabel its just a qstring so i can mix it with the code generated from designer. Any idea what can i do? do i need to create something like a scoped enum or similar?
-
Hi
Your idea should work but Im wondering if you checked it finds the expected QLabel in the silo.
Do you use setObjectName when you create the labels ?also it does have non 0000
in nameOfLabel.append(QString::number(number));
? -
Hi,
One simple way to do that is to have a dict which keys are the value you want to change and the value is the widget you want to update.