Reputation: 3488
I have a checkbox with a slot called
void MainWindow::on_checkBoxPhaseUnwrap_stateChanged(int state)
This is automatically connected.
The constructor of MainWindow is like this
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
{
ui->setupUi(this);
setupWidgets();
}
In setupWidgets
I set the value of the checkbox
ui->checkBoxPhaseUnwrap->setChecked(true);
However the slot is not called, and thus the data base in the background not updated.
Once the window is shown I can click on the checkbox and the slot is called as usual. Why is it not called when I call setChecked
Note: In the gui designer the default value is already checked
. Is this the reason?
Upvotes: 1
Views: 170
Reputation: 1125
In the gui designer the default value is already checked. Is this the reason?
Yes void QCheckBox::stateChanged(int state)
This signal is emitted whenever the checkbox's state changes, i.e., whenever the user checks or unchecks it.
That means it is not emitted if you try to change state from Qt::Checked
to Qt::Checked
.
Solution would be to emit signal yourself:
In setupWidgets
add
emit ui->checkBoxPhaseUnwrap->stateChanged(Qt::Checked);
Upvotes: 2