Question about Constructor
Aug 28, 2010 at 3:52pm UTC
Actually, I have a C++ program in which I want to make a timer. The timer must be declared and created at the constructor of the program...What does this means?
This is the program:
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 26
#include <stdio.h>
#include <time.h>
#include <iostream>
#include <QTimer>
using namespace std;
time_t seconds = time (NULL);
int main ()
{
QTimer *timer = new QTimer(this );
connect(timer, SIGNAL(timeout()), this , SLOT(update_time()));
timer->start(1000);
return 0;
}
void update_time()
{
int a=1;
while (a){
time_t seconds;
seconds = time (NULL);}
}
As you understood, I wanna get the time since 1/1/1970 in seconds and to be updated every single second.... Unfortunately, these two:
1 2 3
QTimer *timer = new QTimer(this );
connect(timer, SIGNAL(timeout()), this , SLOT(update_time()));
have to be moved into the constructor of the application. How can I do this and what does it mean?
Ask like you'd talk to a newbie plz
Thx!
Topic archived. No new replies allowed.