Time for action – the logic of the dialog
Now, it is time to make our game settings dialog work. Earlier, we declared a signal-slot connection but now the slot itself needs to be implemented.
Open the form class generated by Creator. If you're still in the Design mode, you can quickly jump to the respective form class file using the Shift + F4 keyboard shortcut. Create a public slots section of the class and declare a void updateOKButtonState()
slot. Open the refactorization menu (Alt + Enter) and ask Creator to create the skeleton implementation of the slot for you. Fill the function body with the following code:
void ConfigurationDialog::updateOKButtonState() { bool pl1NameEmpty = ui->player1Name->text().isEmpty(); bool pl2NameEmpty = ui->player2Name->text().isEmpty(); QPushButton *okButton = ui->buttonBox->button(QDialogButtonBox::Ok); okButton->setDisabled(pl1NameEmpty || pl2NameEmpty); }
This code retrieves player names and checks whether either of...