_time.h
#ifndef _TIME_H
#define _TIME_H
#include <QObject>
#include <QTimer>
{
Q_OBJECT
public:
//CMTime();
CMTime(int sec=0,int min=0,int hour=0);
void startTicking();
int getHour();
int getMin();
int getSec();
int getTotalSeconds();
static QString getTime
(int h,
int m,
int s
);
private:
int hour;int min;int sec;
signals:
void secondPast(int h,int m,int s);
public slots:
void timeout();
};
#endif // _TIME_H
#ifndef _TIME_H
#define _TIME_H
#include <QObject>
#include <QTimer>
class CMTime : public QObject
{
Q_OBJECT
public:
//CMTime();
CMTime(int sec=0,int min=0,int hour=0);
void startTicking();
QString stop();
QString restart();
int getHour();
int getMin();
int getSec();
int getTotalSeconds();
static QString getTime(int h,int m, int s);
private:
QTimer *timer;
int hour;int min;int sec;
signals:
void secondPast(int h,int m,int s);
public slots:
void timeout();
};
#endif // _TIME_H
To copy to clipboard, switch view to plain text mode
_time.cpp
#include "_time.h"
/*CMTime::CMTime()
{
timer=new QTimer(this);
hour=0;
min=0;
sec=0;
QObject::connect(timer,SIGNAL(timeout()),this,SLOT(timeout()));
}*/
CMTime::CMTime(int s, int m, int h)
{
if (h > -1)
hour=h;
else
hour=0;
if ((m > -1) && (m<60))
min=m;
else
min=0;
if ((s > -1) && (s<60))
sec=s;
else
sec=0;
QObject::connect(timer,
SIGNAL(timeout
()),
this,
SLOT(timeout
()));
}
int CMTime::getHour()
{
return hour;
}
int CMTime::getMin()
{
return min;
}
int CMTime::getSec()
{
return sec;
}
void CMTime::timeout()
{
emit secondPast(hour,min,sec);
if (sec++ == 59)
{
sec=0;
if (min++ == 59)
{
min=0;
hour++;
}
}
}
{
QString result
=getTime
(getHour
(),getMin
(),getSec
());
sec=0;
hour=0;
min=0;
startTicking();
return result;
}
int CMTime::getTotalSeconds()
{
return (sec + (min * 60) + ((hour * 60) * 60));
}
QString CMTime
::getTime(int h,
int m,
int s
) {
QString sStr;QString mStr;QString hStr;
resultTime= hStr+ ":"+mStr+":"+sStr;
return resultTime;
}
void CMTime::startTicking()
{
timer->start(1000);
}
{
timer->stop();
return getTime(getHour(),getMin(),getSec());
}
#include "_time.h"
/*CMTime::CMTime()
{
timer=new QTimer(this);
hour=0;
min=0;
sec=0;
QObject::connect(timer,SIGNAL(timeout()),this,SLOT(timeout()));
}*/
CMTime::CMTime(int s, int m, int h)
{
timer=new QTimer(this);
if (h > -1)
hour=h;
else
hour=0;
if ((m > -1) && (m<60))
min=m;
else
min=0;
if ((s > -1) && (s<60))
sec=s;
else
sec=0;
QObject::connect(timer,SIGNAL(timeout()),this,SLOT(timeout()));
}
int CMTime::getHour()
{
return hour;
}
int CMTime::getMin()
{
return min;
}
int CMTime::getSec()
{
return sec;
}
void CMTime::timeout()
{
emit secondPast(hour,min,sec);
if (sec++ == 59)
{
sec=0;
if (min++ == 59)
{
min=0;
hour++;
}
}
}
QString CMTime::restart()
{
QString result=getTime(getHour(),getMin(),getSec());
sec=0;
hour=0;
min=0;
startTicking();
return result;
}
int CMTime::getTotalSeconds()
{
return (sec + (min * 60) + ((hour * 60) * 60));
}
QString CMTime::getTime(int h,int m,int s)
{
QString resultTime;
QString sStr;QString mStr;QString hStr;
s < 10 ? sStr="0"+QString::number(s):sStr=QString::number(s);
m < 10 ? mStr="0"+QString::number(m):mStr=QString::number(m);
h < 10 ? hStr="0"+QString::number(h):hStr=QString::number(h);
resultTime= hStr+ ":"+mStr+":"+sStr;
return resultTime;
}
void CMTime::startTicking()
{
timer->start(1000);
}
QString CMTime::stop()
{
timer->stop();
return getTime(getHour(),getMin(),getSec());
}
To copy to clipboard, switch view to plain text mode
_process.h:
#ifndef PROCESS_H
#define PROCESS_H
#include <QThread>
#include "_time.h"
#include <QTreeWidget>
{
Q_OBJECT
public:
CMTime t;//<< here it gives error
};
#endif // PROCESS_H
#ifndef PROCESS_H
#define PROCESS_H
#include <QThread>
#include "_time.h"
#include <QTreeWidget>
class CMProcess : public QThread
{
Q_OBJECT
public:
explicit CMProcess(QTreeWidget *parent,QWidget *parentWid);
CMTime t;//<< here it gives error
};
#endif // PROCESS_H
To copy to clipboard, switch view to plain text mode
Bookmarks