Getting QTimeLine and QProgressBar to work
-
I am trying to get a timeline and a progress bar to work. The relevant code snippet is as follows:
@
void dlg_player::play() /// Slot from button clicked signal
}
...
calcLen(plLen);
ui->lbl_plen->setText(plLen);
start();
}void dlg_player::start()
{
ui->progressBar->setRange(0,100); /// ui from Qt designer.
QTimeLine *timeLine = new QTimeLine(mSecs, this);
timeLine->setFrameRange(0, 100);
connect(timeLine, SIGNAL(frameChanged(int)),
ui->progressBar,SLOT(setValue(int))); /// ui from Qt designer
timeLine->start(); /// Is this required?
}void dlg_player::calcLen(QString plLen) /// Calculates m Secs from a "(mm:ss)" string
{
if(plLen.contains('(')) plLen.remove('(');
if(plLen.contains(')')) plLen.remove(')');
playLen = plLen;
mSecs = HMStoSecs(playlLen) * 1000;
}
@It compiles and the debugger shows all variables as correct. The program starts OK but the progress bar does nothing.
Any help or advice would be greatly appreciated.
Thank you.
Graham -
what is the start value of progress bar ? Definitely start is required.
try setting bar->setValue(0)
-
Thank you for your prompt reply.
I tried ui->progressBar->setValue(0); in my code.
(It was already set to zero in designer properties, so was the max and min values)
It did not work.
Thank you again
Regards
G -
Hi,
What is mSecs value ?
-
Hi
mSecs is a qint32 and can of course be set to anything from, lets say, zero to one hour in milliseconds = 0 to 3600000 (Unlikely to be this much).
My test code is 8 min 30 sec = 510000 mSecs.
Thanks again
Regards
G -
Wild thought. Can check whether your start method is called first ? Issue may exist there only. Can you put some debug statement and check inside the start method.
I made this sample. See how this works.
@Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QProgressBar *bar = new QProgressBar(this);
bar->setRange(0,100);
bar->setValue(0);
QTimeLine *tim = new QTimeLine(5000,this);
tim->setFrameRange(0,100);
connect(tim,SIGNAL(frameChanged(int)),bar,SLOT(setValue(int)));
tim->start();
}@