1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the documentation of the Qt Toolkit.
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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
44 \title Qt Object Model
46 \brief A description of the powerful features made possible by Qt's dynamic object model.
48 The standard C++ object model provides very efficient runtime
49 support for the object paradigm. But its static nature is
50 inflexibile in certain problem domains. Graphical user interface
51 programming is a domain that requires both runtime efficiency and
52 a high level of flexibility. Qt provides this, by combining the
53 speed of C++ with the flexibility of the Qt Object Model.
55 Qt adds these features to C++:
58 \o a very powerful mechanism for seamless object
59 communication called \l{signals and slots}
60 \o queryable and designable \l{Qt's Property System}{object
62 \o powerful \l{events and event filters}
63 \o contextual \l{i18n}{string translation for internationalization}
64 \o sophisticated interval driven \l timers that make it possible
65 to elegantly integrate many tasks in an event-driven GUI
66 \o hierarchical and queryable \l{Object Trees and Object Ownership}{object
67 trees} that organize object ownership in a natural way
68 \o guarded pointers (QPointer) that are automatically
69 set to 0 when the referenced object is destroyed, unlike normal C++
70 pointers which become dangling pointers when their objects are destroyed
71 \o a \l{metaobjects.html#qobjectcast}{dynamic cast} that works across
75 Many of these Qt features are implemented with standard C++
76 techniques, based on inheritance from QObject. Others, like the
77 object communication mechanism and the dynamic property system,
78 require the \l{Meta-Object System} provided
79 by Qt's own \l{moc}{Meta-Object Compiler (moc)}.
81 The meta-object system is a C++ extension that makes the language
82 better suited to true component GUI programming. Although
83 templates can be used to extend C++, the meta-object system
84 provides benefits using standard C++ that cannot be achieved with
85 templates; see \l{Why Doesn't Qt Use Templates for Signals and
88 \target Identity vs Value
89 \section1 Qt Objects: Identity vs Value
91 Some of the added features listed above for the Qt Object Model,
92 require that we think of Qt Objects as identities, not values.
93 Values are copied or assigned; identities are cloned. Cloning
94 means to create a new identity, not an exact copy of the old
95 one. For example, twins have different identities. They may look
96 identical, but they have different names, different locations, and
97 may have completely different social networks.
99 Then cloning an identity is a more complex operation than copying
100 or assigning a value. We can see what this means in the Qt Object
103 \bold{A Qt Object...}
107 \o might have a unique \l{QObject::objectName()}. If we copy a Qt
108 Object, what name should we give the copy?
110 \o has a location in an \l{Object Trees and Object Ownership}
111 {object hierarchy}. If we copy a Qt Object, where should the copy
114 \o can be connected to other Qt Objects to emit signals to them or
115 to receive signals emitted by them. If we copy a Qt Object, how
116 should we transfer these connections to the copy?
118 \o can have \l{Qt's Property System} {new properties} added to it
119 at runtime that are not declared in the C++ class. If we copy a Qt
120 Object, should the copy include the properties that were added to
125 For these reasons, Qt Objects should be treated as identities, not
126 as values. Identities are cloned, not copied or assigned, and
127 cloning an identity is a more complex operation than copying or
128 assigning a value. Therefore, QObject and all subclasses of
129 QObject (direct or indirect) have their \l{No copy constructor}
130 {copy constructor and assignment operator} disabled.