Hi guys
I've been trying to use QTcreator to display a timer in a dialog or window. I start the timer, then use a delay function, then measure the time elapsed. My goal is to continuously display the time elapsed onto the window, as if I had a live timer, but it seems that every time I output the time elapsed to the window, it only outputs the final time ie if I use a delay of 5 seconds, then my window takes 5 seconds to open, then it displays 5 seconds; when in fact i want the window to open instantly and diplay 1,2,3,4,5.
Here's what I have so far:
void delay()
{
while( QTime::currentTime() < dieTime
) }
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
QElapsedTimer timer;
timer.start();
delay();
connect(timer.elapsed(),SIGNAL(valueChange(int)), ui->progressBar,SLOT(setValue(int))); // but apparently timer.elapsed doesn't work as a const QObject
void delay()
{
QTime dieTime= QTime::currentTime().addSecs(3);
while( QTime::currentTime() < dieTime )
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QElapsedTimer timer;
timer.start();
delay();
connect(timer.elapsed(),SIGNAL(valueChange(int)), ui->progressBar,SLOT(setValue(int))); // but apparently timer.elapsed doesn't work as a const QObject
To copy to clipboard, switch view to plain text mode
Then I tried another approach
for (int i=1; i<=3000; i++)
while (!timer.hasExpired(3000))
{
ui
->lineEdit
->setText
(QString::number(timer.
elapsed()));
// trying to display timer in line edit ui->progressBar->setValue(timer.elapsed()/30); // trying to use a progress bar to track the time
}
for (int i=1; i<=3000; i++)
while (!timer.hasExpired(3000))
{
ui->lineEdit->setText(QString::number(timer.elapsed())); // trying to display timer in line edit
ui->progressBar->setValue(timer.elapsed()/30); // trying to use a progress bar to track the time
}
To copy to clipboard, switch view to plain text mode
Does anyone have good pointers to help me solve this?
Thanks in advance
-Emara
Bookmarks