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

Alexandre Beraud aberaud at infflux.com
Mon Feb 23 15:18:54 CET 2009


Hi,

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


Knapp a écrit :
> This code can be entered at ether point by changing a spinBox for each
> value, HT or FP. I am still at the learning stages of both C++ and QT.
> I was hoping that someone could suggest a more concise or readable bit
> of code. The best way would be if label_HT could change the FP spin
> box without causing it to call itself. It seems that setValue is just
> like clicking the spinBox.
>
> 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
> }
>
>   


-- 
BERAUD Alexandre
Ingénieur Développement

Infflux - Informatique & Flux
Tel: 01 49 57 92 00 - Fax : 01 49 57 92 01
Mail: aberaud at infflux.com
Visitez notre site :  www.infflux.com





More information about the Qt-interest-old mailing list