title: How to use QTimer
body: <p>In Qt I'm trying to set a <code>QTimer</code> that calls a function called "update" every second. Here is my .cpp file:</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  #include &lt;QTimer&gt;
  #include "QDebug"
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
  
      QTimer *timer = new QTimer(this);
      connect(timer, SIGNAL(timeout()), this, SLOT(update()));
      timer-&gt;start(1000);
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  
  void MainWindow::update()
  {
      qDebug() &lt;&lt; "update";
  }
  </code></pre>
  
  <p>and the main:</p>
  
  <pre><code>#include &lt;QtGui/QApplication&gt;
  #include "mainwindow.h"
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();
  
      return a.exec();
  }
  </code></pre>
  
  <p>The project is being build, but it doesn't execute update, since the line "update" is not showing anywhere... Does anybody see what I´m doing wrong?</p>