[Qt-interest] Is there a better way to code this to prevent recursive calling?
Knapp
magick.crow at gmail.com
Tue Feb 24 10:30:59 CET 2009
>An ugly (but efficient) way of preventing it from calling itself is with
>QObject::blockSignals(bool) before and after the call to setValue()
>(argument true before, and false after).
>Regards,
>Alex
New way verses old way. Not nearly as ugly as the old code! Both code
pieces do the exact same thing and work.
Thanks.
>> void MainWindow::label_HT_Cost_Set(int Num)
>> {
>> dHT = Num - old_HT;
>> old_HT = Num;
>> ui->label_HT_Cost_2->setNum((Num-10)*10);
>> adjust_FP(-99);
>> adjust_Unspent_Points();
>> }
>>
>> void MainWindow::adjust_FP(int Num)
>> {
>> if (Num==-99) { // entered by HT
>> count_FP += 1;
>> ui->spinBox_FP_2->setValue(old_FP+dHT);
>> old_FP += dHT;
>> }
>> else if (count_FP == 0 ) { // entered by changing spinBox
>> count_FP += 1;
>> dFP = Num - old_FP;
>> cost_FP += dFP * 3;
>> ui->label_FP_Cost_2->setNum(cost_FP);
>> ui->spinBox_FP_2->setValue(old_FP+dFP);
>> old_FP = Num;
>> count_FP = 0;
>> adjust_Unspent_Points();
>> }
>> else count_FP = 0; //entered by a looping repeat
>> }
>>
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();
}
void MainWindow::adjust_FP(int Num) {
real_FP = Num - (ui->spinBox_HT_2->value() - 10);
ui->label_FP_Cost_2->setNum((real_FP - 10) * 3);
adjust_Unspent_Points();
//ui->labeldST->setNum(real_FP); // test output
//ui->labeloldST->setNum(Num); // test output
//ui->labelData->setNum(ui->spinBox_HT_2->value() ); // test output
}
--
Douglas E Knapp
Why do we live?
More information about the Qt-interest-old
mailing list