1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
7 \ingroup qt-basic-concepts
8 \brief A description of the powerful features made possible by Qt's dynamic object model.
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.
17 Qt adds these features to C++:
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
24 \li powerful \l{The Event System}{events and event filters}
25 \li contextual \l{Internationalization with Qt}{string translation for
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
36 \li support for \l{Creating Custom Qt Types}{custom type} creation.
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)}.
45 The meta-object system is a C++ extension that makes the language
46 better suited to true component GUI programming.
48 \section1 Important Classes
50 These classes form the basis of the Qt Object Model.
52 \annotatedlist objectmodel
54 \target Identity vs Value
55 \section1 Qt Objects: Identity vs Value
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.
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
73 \li might have a unique \l{QObject::objectName()}. If we copy a Qt
74 Object, what name should we give the copy?
76 \li has a location in an \l{Object Trees & Ownership}
77 {object hierarchy}. If we copy a Qt Object, where should the copy
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?
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
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.