[Qt-interest] Is there a better way to code this to prevent recursive calling?

Sean Harmer sean.harmer at maps-technology.com
Tue Feb 24 11:28:52 CET 2009


Hi,

On Tuesday 24 February 2009 09:30:59 Knapp wrote:
> void MainWindow::label_HT_Cost_Set(int Num)
> {
>     ui->label_HT_Cost_2->setNum((Num-10)*10);
>
>     ui->spinBox_FP_2->blockSignals(TRUE); // adjust_FP but not the cost of
> it. ui->spinBox_FP_2->setValue(real_FP + ui->spinBox_HT_2->value() - 10);
> ui->spinBox_FP_2->blockSignals(FALSE);
>
>     adjust_Unspent_Points();
> }
This would be better as:

void MainWindow::label_HT_Cost_Set(int Num)
{
    ui->label_HT_Cost_2->setNum((Num-10)*10);

    bool block = ui->spinBox_FP_2->blockSignals(true); // adjust_FP but not 
the cost of
    it. ui->spinBox_FP_2->setValue(real_FP + ui->spinBox_HT_2->value() - 10);
    ui->spinBox_FP_2->blockSignals(block);

    adjust_Unspent_Points();
}

i.e. use true not TRUE and restore the original value of blockSignals rather 
than assuming it was false to start with.

ATB,

Sean



More information about the Qt-interest-old mailing list