You'll be interested in 2 functions:
Usually, the "OK" button in a QDialog is connected to the QDialog::accept()
slot. You want to avoid this. Instead, write your own handler to set the return value:
// Custom dialog's constructor
MyDialog::MyDialog(QWidget *parent = nullptr) : QDialog(parent)
{
// Initialize member variable widgets
m_okButton = new QPushButton("OK", this);
m_checkBox1 = new QCheckBox("Option 1", this);
m_checkBox2 = new QCheckBox("Option 2", this);
m_checkBox3 = new QCheckBox("Option 3", this);
// Connect your "OK" button to your custom signal handler
connect(m_okButton, &QPushButton::clicked, [=]
{
int result = 0;
if (m_checkBox1->isChecked()) {
// Update result
}
// Test other checkboxes and update the result accordingly
// ...
// The following line closes the dialog and sets its return value
this->done(result);
});
// ...
}