qtenumsqt5qt5.12

How do I get a child of a QDialog (access a button) with an enum?


I've got a button, assigned to a QDialog this way:

QPushButton *button = ui->buttonBox->button(QDialogButtonBox::StandardButton::Ok);

How do I get it as a child from a QDialog?

I wanted to use:

parentWidget->findChild<QPushButton*>(QDialogButtonBox::StandardButton::Ok);

but findChild<T> needs a QString.

Any suggestions?


Solution

  • Get the buttonBox by its object name first, and then you can get the button you want:

    QDialogButtonBox* buttonBox = dialog.findChild<QDialogButtonBox*>("buttonBox");
    if (buttonBox)
    {
        QPushButton* btn = buttonBox->button(QDialogButtonBox::Ok);
        if (btn)
        {
            qDebug() << "Find it!";
        }
    }