PDA

View Full Version : QDialogButtonBox ResetRole



mero
12th January 2011, 12:52
I have QDialogButtonBox with "Reset" "OK" and "Close"
To OK and Close I use:


QObject::connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(button_ok()));
QObject::connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(button_close()));


How write code to Reset button ? I don't find any examples for ResetRole ...

Lykurg
12th January 2011, 13:01
See the QDialogButtonBox::clicked() signal.

mero
12th January 2011, 13:48
something like this ?



...
QObject::connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttons(QAbstractButton*)));
}

void class::buttons(QAbstractButton *button)
{
if (button->text() == tr("Reset"))
button_reset();
else if (button->text() == tr("OK"))
button_ok();
else if (button->text() == tr("Close"))
button_close();
}

Lykurg
12th January 2011, 13:57
Yes, but better:

if (ui.buttonBox->button(QDialogButtonBox::Help) == button)
// Help was clicked

elettronik
10th May 2011, 10:39
In qt 4.7 I found that a beter solution is


if(ui->buttonBox->standardButton(button) == QDialogButtonBox::Reset)
{
//Do Something
}

Lykurg
10th May 2011, 10:58
And would you kindly elaborate, why your solution is better? It seems to me you are saying that
int i = 1 + 2; is better than
int i = 2 + 1;