Qt 5.10 Book Examples
MyWorker.h
Go to the documentation of this file.
1 // ======================================================================
2 // MyThread.cpp
3 // ======================================================================
4 // This file is a part of the book
5 // "Qt 5.10 Professional programming with C++"
6 // http://qt-book.com
7 // ======================================================================
8 // Copyright (c) 2017 by Max Schlee
9 // ======================================================================
10 
11 #pragma once
12 
13 #include <QtWidgets>
14 
15 // ======================================================================
16 class MyWorker : public QObject {
17 Q_OBJECT
18 private:
19  int m_nValue;
20  QTimer* m_ptimer;
21 
22 public:
23  MyWorker(QObject* pobj = 0) : QObject(pobj)
24  , m_nValue(10)
25  {
26  m_ptimer = new QTimer(this);
27 
28  connect(m_ptimer, SIGNAL(timeout()), SLOT(setNextValue()));
29  }
30 
31 signals:
32  void valueChanged(int);
33  void finished ( );
34 
35 public slots:
36  void slotDoWork()
37  {
38  m_ptimer->start(1000);
39  }
40 
41 private slots:
42  void setNextValue()
43  {
44  emit valueChanged(--m_nValue);
45 
46  if(!m_nValue){
47  m_ptimer->stop();
48  emit finished();
49  }
50  }
51 };
void valueChanged(int)
MyWorker(QObject *pobj=0)
Definition: MyWorker.h:23
void finished()
void slotDoWork()
Definition: MyWorker.h:36