1 #include "mytype.h"
2 
3 #include <QTimer>
4 #include <QTime>
5 #include <qqml.h>
6 
MyType(QObject * parent)7 MyType::MyType(QObject *parent)
8     : QObject(parent)
9 {
10     updateTimerText();
11     m_timer = new QTimer(this);
12     m_timer->setInterval(1000);
13     connect(m_timer, &QTimer::timeout, this, &MyType::updateTimerText);
14     m_timer->start();
15 }
16 
timeText() const17 QString MyType::timeText() const
18 {
19     // bp here should be hit on every second
20     return m_timeText;
21 }
22 
setTimeText(const QString & text)23 void MyType::setTimeText(const QString &text)
24 {
25     if (m_timeText != text) {
26         m_timeText = text;
27         emit timeChanged(m_timeText);
28     }
29 }
30 
updateTimerText()31 void MyType::updateTimerText()
32 {
33     const QTime t = QTime::currentTime();
34     setTimeText(t.toString(QLatin1String("HH:mm:ss")));
35 }
36 
37 QML_DECLARE_TYPE(MyType)
38