|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the documentation of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 /*! |
|
43 \page object.html |
|
44 \title Qt Object Model |
|
45 \brief A description of the powerful features made possible by Qt's dynamic object model. |
|
46 |
|
47 \ingroup frameworks-technologies |
|
48 |
|
49 The standard C++ object model provides very efficient runtime |
|
50 support for the object paradigm. But its static nature is |
|
51 inflexibile in certain problem domains. Graphical user interface |
|
52 programming is a domain that requires both runtime efficiency and |
|
53 a high level of flexibility. Qt provides this, by combining the |
|
54 speed of C++ with the flexibility of the Qt Object Model. |
|
55 |
|
56 Qt adds these features to C++: |
|
57 |
|
58 \list |
|
59 \o a very powerful mechanism for seamless object |
|
60 communication called \l{signals and slots} |
|
61 \o queryable and designable \l{Qt's Property System}{object |
|
62 properties} |
|
63 \o powerful \l{events and event filters} |
|
64 \o contextual \l{i18n}{string translation for internationalization} |
|
65 \o sophisticated interval driven \l timers that make it possible |
|
66 to elegantly integrate many tasks in an event-driven GUI |
|
67 \o hierarchical and queryable \l{Object Trees and Object Ownership}{object |
|
68 trees} that organize object ownership in a natural way |
|
69 \o guarded pointers (QPointer) that are automatically |
|
70 set to 0 when the referenced object is destroyed, unlike normal C++ |
|
71 pointers which become dangling pointers when their objects are destroyed |
|
72 \o a \l{metaobjects.html#qobjectcast}{dynamic cast} that works across |
|
73 library boundaries. |
|
74 \endlist |
|
75 |
|
76 Many of these Qt features are implemented with standard C++ |
|
77 techniques, based on inheritance from QObject. Others, like the |
|
78 object communication mechanism and the dynamic property system, |
|
79 require the \l{Meta-Object System} provided |
|
80 by Qt's own \l{moc}{Meta-Object Compiler (moc)}. |
|
81 |
|
82 The meta-object system is a C++ extension that makes the language |
|
83 better suited to true component GUI programming. Although |
|
84 templates can be used to extend C++, the meta-object system |
|
85 provides benefits using standard C++ that cannot be achieved with |
|
86 templates; see \l{Why Doesn't Qt Use Templates for Signals and |
|
87 Slots?} |
|
88 |
|
89 \section1 Important Classes |
|
90 |
|
91 These classes form the basis of the Qt Object Model. |
|
92 |
|
93 \annotatedlist objectmodel |
|
94 |
|
95 \target Identity vs Value |
|
96 \section1 Qt Objects: Identity vs Value |
|
97 |
|
98 Some of the added features listed above for the Qt Object Model, |
|
99 require that we think of Qt Objects as identities, not values. |
|
100 Values are copied or assigned; identities are cloned. Cloning |
|
101 means to create a new identity, not an exact copy of the old |
|
102 one. For example, twins have different identities. They may look |
|
103 identical, but they have different names, different locations, and |
|
104 may have completely different social networks. |
|
105 |
|
106 Then cloning an identity is a more complex operation than copying |
|
107 or assigning a value. We can see what this means in the Qt Object |
|
108 Model. |
|
109 |
|
110 \bold{A Qt Object...} |
|
111 |
|
112 \list |
|
113 |
|
114 \o might have a unique \l{QObject::objectName()}. If we copy a Qt |
|
115 Object, what name should we give the copy? |
|
116 |
|
117 \o has a location in an \l{Object Trees and Object Ownership} |
|
118 {object hierarchy}. If we copy a Qt Object, where should the copy |
|
119 be located? |
|
120 |
|
121 \o can be connected to other Qt Objects to emit signals to them or |
|
122 to receive signals emitted by them. If we copy a Qt Object, how |
|
123 should we transfer these connections to the copy? |
|
124 |
|
125 \o can have \l{Qt's Property System} {new properties} added to it |
|
126 at runtime that are not declared in the C++ class. If we copy a Qt |
|
127 Object, should the copy include the properties that were added to |
|
128 the original? |
|
129 |
|
130 \endlist |
|
131 |
|
132 For these reasons, Qt Objects should be treated as identities, not |
|
133 as values. Identities are cloned, not copied or assigned, and |
|
134 cloning an identity is a more complex operation than copying or |
|
135 assigning a value. Therefore, QObject and all subclasses of |
|
136 QObject (direct or indirect) have their \l{No copy constructor} |
|
137 {copy constructor and assignment operator} disabled. |
|
138 |
|
139 */ |