Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
employee.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#ifndef EMPLOYEE_H
5#define EMPLOYEE_H
6
7//! [0]
8#include <QSharedData>
9#include <QSharedDataPointer>
10#include <QString>
11
12class EmployeeData : public QSharedData
13{
14public:
15 EmployeeData() : id(-1) {}
17 : QSharedData(other), id(other.id), name(other.name) {}
18 ~EmployeeData() = default;
19
20 int id;
22};
23
24class Employee
25{
26public:
27 //! [1]
28 Employee() { d = new EmployeeData; }
29 //! [1] //! [2]
30 Employee(int id, const QString &name) {
31 d = new EmployeeData;
32 setId(id);
33 setName(name);
34 }
35 //! [2] //! [7]
36 Employee(const Employee &other) = default;
37 Employee &operator=(const Employee &other) = default;
38
39 Employee(Employee &&other) = default;
40 Employee &operator=(Employee &&other) = default;
41
42 ~Employee() = default;
43
44 //! [7]
45 //! [3]
46 void setId(int id) { d->id = id; }
47 //! [3] //! [4]
48 void setName(const QString &name) { d->name = name; }
49 //! [4]
50
51 //! [5]
52 int id() const { return d->id; }
53 //! [5] //! [6]
54 QString name() const { return d->name; }
55 //! [6]
56
57private:
58 QSharedDataPointer<EmployeeData> d;
59};
60//! [0]
61
62#endif
~EmployeeData()=default
QString name
Definition employee.h:21
EmployeeData(const EmployeeData &other)
Definition employee.h:16
Employee & operator=(Employee &&other)=default
QString name() const
Employee(int id, const QString &name)
[1] //! [2]
Definition employee.h:30
Employee & operator=(const Employee &other)
Employee(const Employee &other)
~Employee()=default
int id() const
void setName(const QString &name)
void setId(int id)
Employee(Employee &&other)=default
int main()
[open]