Qtimer and Qprogressbar Connection
-
i have try to get a output as a progress bar runs and endsup with 10Seconds ,Here i am using timer but i dint know how to connect , its started and ends with its own timing , i want to get a output as a progress bar load with 10 seconds only and after that i want to close it . i have attached my code , Give some suggestion for this , Thanks in advance
Timer::Timer(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *layout = new QHBoxLayout();
popup_progress = new QProgressBar();
popup_progress->setMinimum(0);
popup_progress->setMaximum(50);layout->addWidget(popup_progress); setLayout(layout); popupPB = new QTimer(this); connect(popupPB, &QTimer::timeout, this, &Timer::SetValueProgress); popupPB->start(10000); setWindowTitle(tr("popup")); resize(300, 0);
}
void Timer::SetValueProgress()
{
popup_progress->setValue(popup_progress->value()+1);
int value = popup_progress->value();
popup_progress->setValue(value);}
-
@sankarapandiyan
Difficult to know what you mean. You want a progress bar which appears for 10 seconds and then disappears? During that 10 seconds, how do you want it to be updated? Do you mean, say, once per second for the 10 seconds, with each second being 10%?The code you show has a progress bar moving from 0 to 50 in ticks of 1 every 10 seconds. So I make it 500 seconds till it reaches 100%.
-
@JonB said in Qtimer and Qprogressbar Connection:
Do you mean, say, once per second for the 10 seconds, with each second being 10%?
this one i want to do
-
@sankarapandiyan
Ok, so you want:-
popupPB->start(1000);
That's 1,000 ms == 1 second. So now your timer ticks once per second. -
popup_progress->setMaximum(10);
You only need 10 ticks to fill your progress bar,+ 1
at a time. -
Either count the ticks till they reach 10, or look at the
popup_progress->value()
. Once it has reached 10 (or on the next tick, as you please), disconnect the timer and get rid of it and the progress bar.
-
-
@JonB said in Qtimer and Qprogressbar Connection:
popup_progress->setMaximum(10);
Yes this is i want thanks @JonB