Hi,
I'm trying to make a widget to handle time.
timer.h
#ifndef Timer_H
#define Timer_H
#include <QWidget>
{
Q_OBJECT
public:
Timer();
int getHour();
int getMinute();
int getSecond();
int secondValue() const;
void show();
public slots:
void addSecond();
signals:
void secondChanged(int);
private:
int hour;
int minute;
int second;
};
#endif
#ifndef Timer_H
#define Timer_H
#include <QWidget>
class QLabel;
class Timer : public QWidget
{
Q_OBJECT
public:
Timer();
int getHour();
int getMinute();
int getSecond();
int secondValue() const;
void show();
public slots:
void addSecond();
signals:
void secondChanged(int);
private:
int hour;
int minute;
int second;
QLabel *l;
};
#endif
To copy to clipboard, switch view to plain text mode
-----------------------------------------------------
timer.cpp
#include <QtGui>
#include "timer.h"
{
hour = 0;
minute = 0;
second = 0;
}
void Timer::addSecond()
{
second++;
if(second == 60)
{
minute++;
second = 0;
if(minute == 60)
{
hour++;
minute = 0;
}
}
emit secondChanged(second);
}
int Timer::getHour()
{
return hour;
}
int Timer::getMinute()
{
return minute;
}
int Timer::getSecond()
{
return second;
}
int Timer::secondValue() const
{
return second;
}
void Timer::secondChanged(int secondValue)
{
l->setNum(secondValue);
}
void Timer::show()
{
l->show();
}
#include <QtGui>
#include "timer.h"
Timer::Timer() : QWidget()
{
hour = 0;
minute = 0;
second = 0;
l = new QLabel();
}
void Timer::addSecond()
{
second++;
if(second == 60)
{
minute++;
second = 0;
if(minute == 60)
{
hour++;
minute = 0;
}
}
emit secondChanged(second);
}
int Timer::getHour()
{
return hour;
}
int Timer::getMinute()
{
return minute;
}
int Timer::getSecond()
{
return second;
}
int Timer::secondValue() const
{
return second;
}
void Timer::secondChanged(int secondValue)
{
l->setNum(secondValue);
}
void Timer::show()
{
l->show();
}
To copy to clipboard, switch view to plain text mode
I'm getting this error:
debug\moc_timer.o(.text+0x1e0): In function `ZN5Timer13secondChangedEi':
C:/Projetos/backlog/debug/moc_timer.cpp:77: multiple definition of `Timer::secon
dChanged(int)'
debug\timer.o(.text+0x46a):C:/Projetos/backlog/timer.cpp:52: first defined here
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\backlog.exe] Error 1
mingw32-make[1]: Leaving directory `C:/Projetos/backlog'
mingw32-make: *** [debug] Error 2
What should I do?!?
Bookmarks