How to display time in Progress Bar? In which, hours in one progress bar, minutes in one progress bar and seconds in another progress bar, and it should change as the clock?
Printable View
How to display time in Progress Bar? In which, hours in one progress bar, minutes in one progress bar and seconds in another progress bar, and it should change as the clock?
Create three progress bars and a custom slot connected to a timer that sets the progress bars according to the current time.
I have used the following code: but it does nothing.. Please help me in fixing this:
Code:
#include "dialog.h" #include "ui_dialog.h" #include "QDateTime" #include "QTimer" ui(new Ui::Dialog) { ui->setupUi(this); ui->m_hours->setValue(0); ui->m_minutes->setValue(0); ui->m_seconds->setValue(0); ui->m_hours->setRange(0,23); ui->m_minutes->setRange(0,59); ui->m_seconds->setRange(0,59); connect(timer, SIGNAL(timeout()), this, SLOT(prgCtrl())); timer->start(); } Dialog::~Dialog() { delete ui; } { switch (e->type()) { ui->retranslateUi(this); break; default: break; } } void Dialog::prgCtrl() { ui->m_hours->setValue(dt.time().hour()); ui->m_minutes->setValue(dt.time().minute()); ui->m_seconds->setValue(dt.time().second()); }
Why would it do anything if you assign the same values every time?
wysota, this is current time not this same value.
Gokulnathvc, what is it does nothing ? This code looks good. Show us rest of code, especially how You create an instance of Dialog.
Is void Dialog:: prgCtrl(); declared as slot ?
Can you see the debug message ?Code:
void Dialog::prgCtrl() { qDebug() << "update" << dt; ui->m_hours->setValue(dt.time().hour()); ui->m_minutes->setValue(dt.time().minute()); ui->m_seconds->setValue(dt.time().second()); }
Another thing is that you can set one second interval for timer, IMHO there is no need for more frequent ui updates in that case.
I have modified my program after Wysota's advice and then i edited here.