Hi. I have numerous checkboxes that are each linked with a respective Spinbox. What I am trying to accomplish, with minimal code, is to append a suffix to the spinbox when the checkbox is checked. I have 8 sets of checkboxes/spinboxes and I am trying to make them utilize a single slot to accomplish my needs. I have tried the following by it seems a slot will not take a parameter unless it is emited by the accompanying signal. I was told briefly that QSignalMapper may be able to fit my needs but I am unsure. Any guidance would be appreciated! Thanks.
Connection:
for (int i = 1; i <= 8; i++)
{
connect(checkbox_[i], SIGNAL(toggled(bool)), this, SLOT(append_suffix(bool, [i])));
}
QCheckBox* check_[8];
QDoubleSpinBox* grade_SpinBox_[8];
for (int i = 1; i <= 8; i++)
{
connect(checkbox_[i], SIGNAL(toggled(bool)), this, SLOT(append_suffix(bool, [i])));
}
To copy to clipboard, switch view to plain text mode
Slot:
void MainWindow::append_suffix(bool clicked, int checkboxnum)
{
if (clicked == false)
{
}
else
{
}
}
void MainWindow::append_suffix(bool clicked, int checkboxnum)
{
if (clicked == false)
{
grade_SpinBox_[checkboxnum]->setSuffix(QApplication::translate("MainWindow", "%", 0, QApplication::UnicodeUTF8));
}
else
{
ass_grade_SpinBox_[checkboxnum]->setSuffix(QApplication::translate("MainWindow", "", 0, QApplication::UnicodeUTF8));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks