Try passing the pointer to the label, i.e.lblStatus1 ,lblStatus2 etc., rather than the index:
void ControlPanel
::setStatus(int id,
QLabel *label
) { Q_ASSERT(label); // to catch yourself if you pass a NULL during development
switch(id) {
case 1:
label->setText(...);
label->setStyleSheet(...);
break;
case 2:
// stuff for id 2
break;
....
default:
// Unexpected value?
break;
}
}
void ControlPanel::setStatus(int id, QLabel *label) {
Q_ASSERT(label); // to catch yourself if you pass a NULL during development
switch(id) {
case 1:
label->setText(...);
label->setStyleSheet(...);
break;
case 2:
// stuff for id 2
break;
....
default:
// Unexpected value?
break;
}
}
To copy to clipboard, switch view to plain text mode
You might then ask yourself if there are more efficient ways to do this as well, e.g. is the label text is the same as the id number, can you derive or lookup the colour value?
Bookmarks