Hobrasoft httpd server
Embedded HTTP server for Qt and C++
item.cpp
Go to the documentation of this file.
1 
5 #include "item.h"
6 
7 #include <QObject>
8 #include <QString>
9 #include <QVariantMap>
10 
11 using namespace Example;
12 
13 Item::Item(const QString& id, const QString& text, int interval, QObject *parent) : QObject(parent) {
14  m_id = id;
15  m_text = text;
16  m_counter = 0;
17 
18  m_timer = new QTimer(this);
19  m_timer->setInterval(interval);
20  m_timer->setSingleShot(false);
21  m_timer->start();
22  connect (m_timer, SIGNAL(timeout()), this, SLOT(updateStatus()));
23 }
24 
25 
27  m_counter++;
28  emit statusChanged(this);
29 }
30 
31 
32 const QString& Item::id() const {
33  return m_id;
34 }
35 
36 
37 const QString& Item::text() const {
38  return m_text;
39 }
40 
41 
42 QVariantMap Item::webStatus() const {
43  QVariantMap data;
44  data["id"] = m_id;
45  data["text"] = m_text;
46  data["counter"] = m_counter;
47  return data;
48 }
49 
void statusChanged(const Item *)
Signal is invoked when the status of the item changed.
Namespace for Example.
Definition: application.h:11
Item(const QString &id, const QString &text, int interval, QObject *parent)
Constructor creates item from given parameters.
Definition: item.cpp:13
QVariantMap webStatus() const
Returns webStatus of the item.
Definition: item.cpp:42
const QString & text() const
Returns text of the item.
Definition: item.cpp:37
void updateStatus()
Slot is called periodicaly to increment inner value of the example item.
Definition: item.cpp:26
const QString & id() const
Returns id of the item.
Definition: item.cpp:32