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
object.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page object.html
6
\title Object Model
7
\ingroup qt-basic-concepts
8
\brief A description of the powerful features made possible by Qt's dynamic object model.
9
10
The standard C++ object model provides very efficient runtime
11
support for the object paradigm. But its static nature is
12
inflexibile in certain problem domains. Graphical user interface
13
programming is a domain that requires both runtime efficiency and
14
a high level of flexibility. Qt provides this, by combining the
15
speed of C++ with the flexibility of the Qt Object Model.
16
17
Qt adds these features to C++:
18
19
\list
20
\li a very powerful mechanism for seamless object
21
communication called \l{signals and slots}
22
\li queryable and designable \l{Qt's Property System}{object
23
properties}
24
\li powerful \l{The Event System}{events and event filters}
25
\li contextual \l{Internationalization with Qt}{string translation for
26
internationalization}
27
\li sophisticated interval driven \l {Timers}{timers} that make it possible
28
to elegantly integrate many tasks in an event-driven GUI
29
\li hierarchical and queryable \l{Object Trees & Ownership}{object
30
trees} that organize object ownership in a natural way
31
\li guarded pointers (QPointer) that are automatically
32
set to 0 when the referenced object is destroyed, unlike normal C++
33
pointers which become dangling pointers when their objects are destroyed
34
\li a \l{metaobjects.html#qobjectcast}{dynamic cast} that works across
35
library boundaries.
36
\li support for \l{Creating Custom Qt Types}{custom type} creation.
37
\endlist
38
39
Many of these Qt features are implemented with standard C++
40
techniques, based on inheritance from QObject. Others, like the
41
object communication mechanism and the dynamic property system,
42
require the \l{Meta-Object System} provided
43
by Qt's own \l{moc}{Meta-Object Compiler (moc)}.
44
45
The meta-object system is a C++ extension that makes the language
46
better suited to true component GUI programming.
47
48
\section1 Important Classes
49
50
These classes form the basis of the Qt Object Model.
51
52
\annotatedlist objectmodel
53
54
\target Identity vs Value
55
\section1 Qt Objects: Identity vs Value
56
57
Some of the added features listed above for the Qt Object Model,
58
require that we think of Qt Objects as identities, not values.
59
Values are copied or assigned; identities are cloned. Cloning
60
means to create a new identity, not an exact copy of the old
61
one. For example, twins have different identities. They may look
62
identical, but they have different names, different locations, and
63
may have completely different social networks.
64
65
Then cloning an identity is a more complex operation than copying
66
or assigning a value. We can see what this means in the Qt Object
67
Model.
68
69
\b{A Qt Object...}
70
71
\list
72
73
\li might have a unique \l{QObject::objectName()}. If we copy a Qt
74
Object, what name should we give the copy?
75
76
\li has a location in an \l{Object Trees & Ownership}
77
{object hierarchy}. If we copy a Qt Object, where should the copy
78
be located?
79
80
\li can be connected to other Qt Objects to emit signals to them or
81
to receive signals emitted by them. If we copy a Qt Object, how
82
should we transfer these connections to the copy?
83
84
\li can have \l{Qt's Property System} {new properties} added to it
85
at runtime that are not declared in the C++ class. If we copy a Qt
86
Object, should the copy include the properties that were added to
87
the original?
88
89
\endlist
90
91
For these reasons, Qt Objects should be treated as identities, not
92
as values. Identities are cloned, not copied or assigned, and
93
cloning an identity is a more complex operation than copying or
94
assigning a value. Therefore, QObject and all subclasses of
95
QObject (direct or indirect) have their \l{No copy constructor}
96
{copy constructor and assignment operator} disabled.
97
98
*/
qtbase
src
corelib
doc
src
objectmodel
object.qdoc
Generated on
for Qt by
1.14.0