Qt 5.10 Book Examples
Calculation.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // Calculation.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 #include "Calculation.h"
12 
13 // ----------------------------------------------------------------------
14 Calculation::Calculation(QObject* pobj) : QObject(pobj)
15  , m_nInput(0)
16  , m_nResult(1)
17 {
18 }
19 
20 // ----------------------------------------------------------------------
21 qulonglong Calculation::factorial(const qulonglong& n)
22 {
23  return n ? (n * factorial(n - 1)) : 1;
24 }
25 
26 // ----------------------------------------------------------------------
27 qulonglong Calculation::inputValue() const
28 {
29  return m_nInput;
30 }
31 
32 // ----------------------------------------------------------------------
33 qulonglong Calculation::resultValue() const
34 {
35  return m_nResult;
36 }
37 
38 // ----------------------------------------------------------------------
39 void Calculation::setInputValue(const qulonglong& n)
40 {
41  m_nInput = n;
42  m_nResult = factorial(m_nInput);
43 
44  emit inputValueChanged(m_nInput);
45  emit resultValueChanged(m_nResult);
46 }
47 
void resultValueChanged(qulonglong)
Q_INVOKABLE qulonglong factorial(const qulonglong &n)
Definition: Calculation.cpp:21
void setInputValue(const qulonglong &)
Definition: Calculation.cpp:39
qulonglong resultValue() const
Definition: Calculation.cpp:33
void inputValueChanged(qulonglong)
Calculation(QObject *pobj=0)
Definition: Calculation.cpp:14
qulonglong inputValue() const
Definition: Calculation.cpp:27