How to make a simple stopwatch in C++

Hello everyone,

I'm new to C++ (not much programming experience, except for have been trying to learn Ruby and before that KBasic (now Q7Basic I believe)) and of course this forum. I'm making a little stopwatch application with Qt (using Qt Creator 4.8). The functions are record a time, save times from different people in different XML files. And read the XML files later on to view the previously recorded times. With a dropdown menu you can select.

The first step is let a C++ program simply count seconds as stopwatch. Does any one know how to simply let a program count 1,2,3 etc. ?

Kind Regards,

Superpelican

P.S. I'm using LInux
You could use the ctime header, but since you're already using Qt, why not use the timer function?
http://doc.qt.nokia.com/4.7-snapshot/timers.html
Well I followed this (http://www.developer.nokia.com/Community/Wiki/How_to_use_QTimer_in_Qt) tutorial, which I found easier to understand than Qt' s tutorial. Now I have this code, my "mainwindow.cpp":

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_commandLinkButton_clicked()
{
   WRC_Timer = new QTimer(this);
   WRC_Timer->setInterval(1);
   WRC_Timer->start();
   QObject::connect(WRC_Timer, SIGNAL(timeout()), this, SLOT(WRC_Timer_TimeOut()));


}

void WRC_Timer_Timeout() {
 //My code
}


And Qmake (within Qt Creator) reports this Build Issue:

‘WRC_Timer’ was not declared in this scope


While I'm sure I declared it in:

WRC_Timer = new QTimer(this);
Didn't I?
Topic archived. No new replies allowed.