-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyclass.cpp
55 lines (45 loc) · 1017 Bytes
/
myclass.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "myclass.h"
#include <QDateTime>
#include <QDebug>
#include <QTimer>
MyClass::MyClass(QObject *parent) :
QObject(parent),
m_timer(new QTimer)
{
QObject::connect(m_timer, &QTimer::timeout, [&](){
this->setClock(QDateTime::currentDateTime().toString("HH:MM:ss"));
qInfo().noquote().nospace() << "Tick: " << QDateTime::currentDateTime().toString("HH:MM:ss");
});
}
MyClass::~MyClass()
{
if (m_timer) {
delete m_timer;
m_timer = nullptr;
}
}
QString MyClass::clock() const
{
return m_clock;
}
void MyClass::newValuePot(int value)
{
qsrand(QDateTime::currentDateTime().toTime_t());
qInfo().noquote().nospace() << "New Value[" << qrand()%value <<"]";
Q_EMIT newData(qrand()%value);
}
void MyClass::startTimer()
{
m_timer->start(1000);
}
void MyClass::stopTimer()
{
m_timer->stop();
}
void MyClass::setClock(QString time)
{
if (m_clock == time)
return;
m_clock = time;
Q_EMIT changedClock(m_clock);
}