SetPercent() not working...
-
Hi,
I am using ProgressDialog() class to show the progress bar in my plugin. I got the example from here.
This example works fine and shows a good progress bar but when I customized it to use for my code it stopped showing the progress percentage which was set using SetPercent().
Here is my code :void ProgressBarDialog::Timer(const BaseContainer &msg) { GePrint("ProgressBarDialog::Timer() is called."); GePrint("value of percentIncrease = " + String::FloatToString((percentIncrease))); percentIncrease += 2.0f; SetPercent(percentIncrease/100); }
Also if I am using the SetPercent() in *void ProgressBarDialog::Main(C4DThread bt) function of ProgressDialog(), it is still not working.
Please help me with this as I am stuck with it for a long time.
Thanks In Advance.
-
@gogeta said in SetPercent() not working...:
percentIncrease/100
This results in being an
Int
. Because you divide afloat
by 100 and that results in anInt
rounded to 0.
So simply cast it tofloat
- right as the example you linked, does. -
Hi,
I tried the same as suggested by you but it still didn't work .
I even tried with hardcoded float values but still no progress.
I am not able to understand why is this happening .Update: In Main() function of ProgressDialog class I am doing some task and also updating the progress bar with SetPercent(0.1F), SetPercent(0.2F) and so on.
Please guide me.Thanks.
-
Would you mind to share the relevant portion of your code?
-
@mp5gosu Hi,
I can't provide you the exact code but I am providing some portion of code for understanding. Please have a look into this.
Bool ProgressBarDialog::CreateLayout() { return ProgressDialog::CreateLayout(); } Bool ProgressBarDialog::InitValues() { GePrint("Initializing progress bar values."); //percentIncrease = 0.0F; //this->SetTimer(1000); return ProgressDialog::InitValues(); } void ProgressBarDialog::Main(C4DThread *bt) { percentIncrease = 0.0F; GePrint("In Main function."); Bool status = false; /*some variables*/ ... ... ... String str1; String str2; /*Set progress bar 10%*/ SetPercent(0.1f); DWORD flag = doSomework(); status = readStatus(arg1,arg2,arg3); if (!status) { MessageDialog("Please Try Again. Facing Issue !"); isErrorOccurred = true; return ; } /*Set progress bar 20%*/ SetPercent(0.2f); //StatusSetBar(10); /*some relevant tasks*/ /*Set progress bar 30%*/ SetPercent(0.3f); status = doSomeCommunication(buff1, buff2); /*Set progress bar 60%*/ SetPercent(0.6f); if (!status) { /*Set progress bar 70%*/ SetPercent(0.7f); /*Perform other tasks*/ /*Set progress bar 80%*/ SetPercent(0.8f); } else { /*Set progress bar 70%*/ SetPercent(0.7f); status = doSomeParsing(Buff1, &var1); if (!status) { MessageDialog(buff[0]); //display error msg isErrorOccurred = true; return ; } /*Set progress bar 90%*/ SetPercent(0.9f); /*do some other tasks*/ } /*Set progress bar 100%*/ SetPercent(1.f); } void ProgressBarDialog::Timer(const BaseContainer &msg) { GePrint("ProgressBarDialog::Timer() is called."); GePrint("value of percentIncrease = " + String::FloatToString((percentIncrease))); percentIncrease += 2.0f; SetPercent((Float)percentIncrease / 100); }
Thanks!
-
Hi @gogeta sorry for the late reply.
Since ProgressDialog makes use of a Timer in order to refresh the UI, you must call the Super::Timer operator like so at the end of your Timer function.
return ProgressDialog::Timer(msg);
If you have any questions please let me know!
Cheers,
Maxime. -
@m_adam Hi,
Thanks for your answer. I applied your changes and it worked like a charm .
Thanks again!!!