Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
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
ui->progressBar->setRange(0,100); /// ui from Qt designer.
QTimeLine *timeLine = new QTimeLine(mSecs, this);
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
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.
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
What is mSecs value ?
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.
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.
QProgressBar *bar = new QProgressBar(this);
QTimeLine *tim = new QTimeLine(5000,this);