title: How to properly implement a count down timer in a QLabel
body: <p>In order to shrink the problem I created a minimal verifiable example below.
  I am trying to implement a 60 minutes count down using a <code>QLabel</code>. </p>
  
  <p><strong>The problem</strong> I have is that instead of seeing the time going back, I see the the current time going forward. And no countdown goes back.</p>
  
  <p>Below the minimal verifiable example:</p>
  
  <p><strong>mainwindow.h</strong></p>
  
  <pre><code>#include &lt;QMainWindow&gt;
  #include &lt;QTime&gt;
  #include &lt;QTimer&gt;
  
  QT_BEGIN_NAMESPACE
  namespace Ui { class MainWindow; }
  QT_END_NAMESPACE
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  public:
      MainWindow(QWidget *parent = nullptr);
      ~MainWindow();
  
  public slots:
      void timerUpdate();
  private:
      Ui::MainWindow *ui;
      QTimer *timer;
      QTime time;
  };
  </code></pre>
  
  <p><strong>mainwindow.cpp</strong></p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  
  MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent)
      , ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
      //ui-&gt;countDown-&gt;setText(time.currentTime().toString("hh:mm:ss"));
      ui-&gt;countDown-&gt;setText("60:00");
      //ui-&gt;countDown-&gt;setText(time.toString("hh:mm:ss"));
      timer = new QTimer(this);
      connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate()));
      timer-&gt;start(1000);
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  
  void MainWindow::timerUpdate()
  {
      time = time.addSecs(-1);
      ui-&gt;countDown-&gt;setText(time.currentTime().toString("hh:mm:ss"));
  }
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include "mainwindow.h"
  #include &lt;QApplication&gt;
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();
      return a.exec();
  }
  </code></pre>
  
  <p><strong>EDIT 2</strong></p>
  
  <pre><code>MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent)
      , ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
      //ui-&gt;countDown-&gt;setText(time.toString("hh:mm:ss"));
      //ui-&gt;countDown-&gt;setText("60:00");
      ui-&gt;countDown-&gt;setText(time.toString("hh:mm:ss"));
      timer = new QTimer(this);
      connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate()));
      timer-&gt;start(1000);
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  
  void MainWindow::timerUpdate()
  {
      time = time.addSecs(-1);
      ui-&gt;countDown-&gt;setText(time.toString("hh:mm:ss"));
  }
  </code></pre>
  
  <p>I followed exactly the <a href="https://doc.qt.io/qt-5/qtimer.html#details" rel="nofollow noreferrer">official documentation</a> but despite that it still does not work. In addition to that I consulted also the <a href="https://doc-snapshots.qt.io/qt5-5.11/qtime.html" rel="nofollow noreferrer">QTime</a> class to make sure I was respecting the members function to call.
  I tried also another thign which is setting the constructor to <a href="https://doc-snapshots.qt.io/qt5-5.11/qtime.html#setHMS" rel="nofollow noreferrer">setHMS</a> and providing the proper values related to 1 hour, but that also didn't work.</p>
  
  <p>I dug more and came across <a href="https://crazybaga.blogspot.com/2017/08/qtimer-how-to-work-with-timer.html" rel="nofollow noreferrer">this post</a> which uses a very similar approach to what I used, with the difference that the example implements a current timer and not a count down. That is the reason why in the <code>timerUpdate()</code> function I am diminishing time <code>time = time.addSecs(-1);</code> instead of adding it. But still does not work.</p>
  
  <p>Thanks for pointing in the right direction to solve this problem.</p>