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:

Qt Code:
  1. void delay()
  2. {
  3. QTime dieTime= QTime::currentTime().addSecs(3);
  4. while( QTime::currentTime() < dieTime )
  5. QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
  6. }
  7.  
  8.  
  9. MainWindow::MainWindow(QWidget *parent) :
  10. QMainWindow(parent),
  11. ui(new Ui::MainWindow)
  12. {
  13. ui->setupUi(this);
  14. QElapsedTimer timer;
  15. timer.start();
  16. delay();
  17. 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
Qt Code:
  1. for (int i=1; i<=3000; i++)
  2. while (!timer.hasExpired(3000))
  3. {
  4. ui->lineEdit->setText(QString::number(timer.elapsed())); // trying to display timer in line edit
  5. ui->progressBar->setValue(timer.elapsed()/30); // trying to use a progress bar to track the time
  6. }
To copy to clipboard, switch view to plain text mode 

Does anyone have good pointers to help me solve this?

Thanks in advance

-Emara