source: trunk/doc/src/porting/porting4-overview.qdoc

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 15.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 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:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at qt-info@nokia.com.
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \page porting4-overview.html
30 \title Moving from Qt 3 to Qt 4
31 \ingroup porting
32 \brief Porting advice for authors of new and existing Qt 3 applications.
33
34 This document describes which parts of Qt should be used when
35 writing an application with Qt 3, so that it can be upgraded to
36 use Qt 4 later with a minimum of effort. However, the advice may
37 also be useful to developers who are porting existing applications
38 from Qt 3 to Qt 4.
39
40 For a detailed overview
41 of the porting process for existing Qt 3 applications, see the
42 \l{Porting to Qt 4} document.
43
44 \tableofcontents
45
46 Since Qt 4 provides important new functionality at the cost of
47 some compatibility with Qt 3, it is useful for developers of
48 Qt 3-based applications to learn how to take advantage of
49 Qt 3's API now while preparing for future changes that will be
50 needed when upgrading to Qt 4.
51
52 Certain advanced Qt 3 features were moved to the Qt 3 support
53 library (\l{Qt3Support}) in Qt 4.0, and have been gradually
54 replaced in subsequent releases of Qt 4.
55
56 Making Qt 3 applications as portable to Qt 4 as possible
57 enables a smooth transition between versions of Qt in the
58 long term, and allows for a stable development process
59 throughout.
60
61 \section1 Qt 3 Features to Avoid
62
63 Although we are proud of the level of stability we have achieved
64 with Qt, it is important to realise that, for Qt 4 to be a
65 substantial improvement over Qt 3, certain features have
66 been revised to make the framework more maintainable for us
67 and more usable for developers. It is therefore useful to
68 know which features of Qt 3 should be avoided to help save
69 time during a later porting effort to Qt 4. Note that it is
70 still possible to use many of the following classes and
71 features through the use of the \l{Qt3Support} module.
72
73 \section2 Painting Outside Paint Events
74
75 In Qt 3, under certain circumstances, it was possible to use
76 QPainter to draw on a given custom widget outside its
77 \l{QWidget::}{paintEvent()} reimplementation. In Qt 4, in most
78 situations, painting must occur within a widget's paint event
79 handler.
80
81 On X11, it is possible to set the \l{Qt::WA_PaintOutsidePaintEvent}
82 attribute on widgets to keep existing code, but we recommend
83 restricting the use of painting code to within paint event handlers
84 where possible.
85
86 More information about this change can be found in the
87 \l{Porting to Qt 4#Painting and Redrawing Widgets}{Painting and Redrawing Widgets}
88 section of the \l{Porting to Qt 4} document.
89
90 \section2 Qt Designer
91
92 The version of Qt Designer supplied with Qt 3 provided
93 extensive code editing and project management features
94 (control over \c{.ui.h} and \c{.pro} files), and encouraged
95 users to design main window applications from within the
96 Qt Designer environment.
97
98 The version of Qt Designer supplied with Qt 4 is intended
99 to be integrated with other software development tools (such
100 as integrated development environments), and does not
101 support these project-level features.
102
103 We recommend using one of the
104 \l{Using a Designer UI File in Your Application}{form subclassing approaches}
105 with forms created using Qt Designer. This avoids the need
106 to use \c{.ui.h} files and special purpose code editors.
107
108 Existing Qt 3 forms created using Qt Designer can be gradually
109 ported to Qt 4 by following the advice in the
110 \l{Porting UI Files to Qt 4} guide. However, some extra effort
111 will be required to move application logic from \c{.ui.h} files
112 into the main body of a Qt 4 application.
113
114 \section2 Menu Items (QMenuItem)
115
116 The old-style construction of menus by creating individual
117 menu items has been superseded in Qt 4 by the use of
118 generic actions which can be used in menus, toolbars, and
119 as keyboard shortcuts.
120
121 Qt 3 also supports this action-based approach, so, by using
122 QAction throughout your application, less work will be
123 required to adapt your application to Qt 4.
124
125 \section2 Pointer-Based Classes (QPtr*)
126
127 Qt 3 provides a group of pointer-based classes (\c QPtrList,
128 \c QPtrDict, \c QPtrVector, etc.) that help manage collections
129 of pointers to objects (usually QObject subclasses) in an
130 application. In addition, the value-based collection classes
131 (\c QValueList, \c QValueDict, \c QValueVector, etc.) provide
132 a way to store standard value types which cannot be easily stored
133 in pointer-based collections.
134
135 Qt 4 introduces a single set of collection classes which
136 does not require developers to pay as much attention to
137 memory allocation and object ownership issues. As a result,
138 Qt 3's pointer-based classes have no direct equivalent
139 classes in Qt 4.
140
141 To ease migration, use Qt 3's value-based classes to store
142 most objects, including pointers; for example, use
143 \c QValueVector<QWidget *> rather than
144 \c QPtrVector<QWidget *>. These can be replaced by
145 Qt 4's QVector, QLinkedList, and QList later.
146
147 \section2 Other Collection Classes (QStrList, Q*Dict)
148
149 Some collection classes in Qt 3 have been deprecated in
150 favor of easier to use, higher level alternatives. These
151 include the dictionary classes (\c QAsciiDict, \c QDict,
152 \c QIntDict, \c QPtrDict) and \c QStrList.
153
154 \c QStrList can usually replaced by the higher level QStringList
155 class in Qt 3; this is also available in Qt 4. It is
156 recommended that you use the QMap class instead of the \c QDict
157 classes. In Qt 4, QMap is also complemented by the QHash
158 class.
159
160 \section2 Memory Arrays (QMemArray)
161
162 In Qt 3, the \c QMemArray class is used as a simple array
163 container for simple data types. This class is deprecated in
164 Qt 4 in favor of the QVector and QVarLengthVector classes
165 which provide more powerful and consistent array objects.
166
167 Qt 3's closest equivalent class to Qt 4's QVector is the
168 \c QValueVector class. For many purposes, this can be used
169 instead of \c QMemArray.
170
171 \section2 URL Operations (QUrlOperator)
172
173 The URL operator in Qt 3 provides an abstract way to
174 handle files via HTTP, FTP, and on the local file system.
175 However, Qt 4 only provides this functionality through the
176 use of the Q3UrlOperator.
177
178 From Qt 4.4, the Network Access API provides a subset of the features
179 provided by \c QUrlOperator that are mostly intended for use with
180 applications that use the HTTP and FTP protocols. See the
181 QNetworkRequest, QNetworkReply, and QNetworkAccessManager documentation
182 for further details.
183
184 It is also possible to perform operations on remote files through
185 the QNetworkAccessManager and QFtp classes, and on local files
186 with the QFile class.
187
188 \section2 SQL Cursors (QSqlCursor)
189
190 In Qt 3, one of the preferred methods of working with SQL
191 is to use a cursor to manipulate the contents of a database.
192 In Qt 4, the preferred method of working with SQL is to use
193 the model/view architecture (QSqlQueryModel and QSqlTableModel)
194 and, as a result, the cursor interface is only supplied in the
195 Q3SqlCursor class.
196
197 The easiest way to ensure continuity between Qt 3 and Qt 4
198 is to use QSqlQuery rather than \c QSqlCursor,
199 and migrate to QSqlQueryModel later.
200
201 \section2 Domain Name Service (QDns)
202
203 The QDns class in Qt 4 provides a much simpler interface
204 than the QDns class in Qt 3, and is mainly used for host
205 name resolution.
206 As a result, many of the more complex features of Qt 3's
207 QDns class are only available through Qt 4's Q3Dns
208 compatibility class.
209
210 To resolve host names with Qt 3, it is recommended that you
211 use the higher level interface of QSocket rather than QDns.
212 The equivalent functionality is available in Qt 4 in the
213 QAbstractSocket and QHostInfo classes.
214
215 \section2 Wizard Dialogs (QWizard)
216
217 Qt 3 provides support for "wizard" dialogs in the form of
218 the \c QWizard class. Prior to Qt 4.3, this class was made
219 available as Q3Wizard, and provides the same interface for
220 creating relatively complex wizards.
221
222 In Qt 4.3 and later, a revised QWizard class can be used to
223 create this kind of dialog, but existing Qt 3 wizard
224 implementations may need to be redesigned to work with the
225 new QWizard API.
226
227 \section2 Abstract Grid Views (QGridView)
228
229 Before the introduction of the Qt 3 \c QTable class,
230 \c QGridView was the recommended way to create tables of
231 custom items.
232 With the introduction of \c QTable, the \c QGridView class was
233 effectively obsoleted, and the \c QTable class should now be
234 used to display tabular information in your Qt 3 application.
235 This approach allows you to use QTableWidget as a replacement
236 when later porting your application to Qt 4.
237
238 \section2 Specialized Scrolling Views
239
240 In Qt 3, the \c QScrollView class provides a viewport that can
241 be used to display part of a larger widget, and will
242 optionally provide scroll bars for navigation purposes.
243 In Qt 4, this functionality is superseded by classes such as
244 QScrollArea, which provides a more intuitive interface for
245 developers to use.
246 \c QScrollView is available in Qt 4 as the Q3ScrollView class.
247
248 In Qt 3, it is recommended that \c QScrollView should be
249 used with child widgets rather than subclassed. However, it
250 should be noted that this approach may not be appropriate if
251 you need to use extremely large scrolling areas in your
252 application, since Qt 3 widgets cannot be wider or taller
253 than 32767 pixels.
254
255 \section1 Significantly Changed Features
256
257 Some Qt 3 features have changed significantly for Qt 4.
258 and the recommended way of using them has therefore changed
259 significantly, too. This is most notably true for the drag
260 and drop API.
261
262 Additionally, some of the more specialized features in Qt 3 are
263 often used to help customize widgets and add extra polish to an
264 application.
265 Although these improvements make applications more presentable to
266 users, many of them are unnecessary with Qt 4, and may create
267 additional porting work.
268
269 \section2 Drag and Drop
270
271 Qt 4 introduces a simpler and more intuitive implementation
272 of drag and drop between widgets, and with other applications.
273 As a result, there is no simple approach that can be used to
274 make drag and drop in a Qt 3 application easier to port to
275 Qt 4.
276
277 \section2 Extensive Customization of Item Views
278
279 Each of the classes that are used to display list, tree,
280 and table items in Qt 3 can be subclassed for the purposes
281 of customizing their appearance. The item view framework
282 in Qt 4 is implemented according to a different paradigm
283 (model/view) which does not allow items to be customized
284 using this method.
285
286 Although Qt 4 provides compatibility classes (Q3ListBoxItem,
287 Q3ListViewItem, and Q3TableItem) that can be used in the same
288 way as their Qt 3 counterparts, these cannot be used within
289 the standard model/view framework. It is recommended that,
290 to minimize porting effort, extensive customization of item
291 classes should be avoided in Qt 3, if at all possible.
292
293 \section2 Double Buffering
294
295 Qt 3 applications often use double buffering for reducing
296 flicker when painting custom widgets. This approach is
297 unnecessary with Qt 4 because double buffering is
298 automatically performed by the paint engine.
299
300 It still makes sense to use double buffering in
301 Qt 4 in certain contexts. For example, in
302 Chapter 5 of \l{GUI Programming with Qt 3}, double buffering
303 was presented as a speed optimization and not just as a means
304 of reducing flicker.
305
306 \section2 Data-Aware Forms
307
308 The \c QDataTable, \c QDataBrowser, and \c QDataView classes
309 in Qt 3 allow integration between widgets and SQL-based
310 databases.
311
312 In Qt 4.1 and earlier, the preferred way to create a data-aware
313 widget is to connect an generic item view (such as a table view)
314 to a SQL model. In Qt 4.2 and later, the QDataWidgetMapper class
315 can be used to map data to widgets in a form-based user interface.
316
317 New applications written with Qt 3 should use QSqlQuery in
318 preference to an approach based on the old-style data-aware
319 widgets.
320 This offers a choice of porting strategies when later migrating
321 the application to Qt 4: You can either continue to use
322 QSqlQuery or take the opportunity to use the model/view
323 classes to handle database integration.
324
325 \section2 Dock Windows and Areas
326
327 In Qt 4, the way that dock windows are constructed and used
328 in main window applications differs significantly to the
329 pattern of use provided by Qt 3. As a result, the introduction
330 of a simpler and cleaner API means that Qt 3 applications that
331 make extensive use of dock window areas will require careful
332 examination when they are ported to Qt 4.
333
334 We recommend that the QMainWindow class be used in preference
335 to the Q3MainWindow compatibility class when an existing Qt 3
336 main window application is ported to Qt 4. Therefore, we
337 recommend that specialized use of dock window areas should
338 be avoided when writing a Qt 3 application with Qt 4 in mind.
339
340 \section2 Custom Styles
341
342 The style system used to provide consistent themes for Qt's
343 standard widgets has been revised for Qt 4. As a result,
344 custom styles for Qt 3 require some porting work to be done
345 before they can be used with Qt 4. To ease the porting process,
346 we recommend that you avoid implementing custom widget styles
347 for Qt 3 applications unless it is absolutely necessary for
348 your users.
349
350 In Qt 4.2 and later, \l{Qt Style Sheets} can be used to
351 implement many common modifications to existing styles, and
352 this may be sufficient for Qt 3 applications.
353
354 \section2 Events
355 In Qt 3, QCloseEvents were not accepted by default. In Qt 4,
356 the event handler QWidget::closeEvent() receives QCloseEvents,
357 and accepts them by default closing the application. To avoid
358 this, please reimplement QWidget::closeEvent().
359*/
Note: See TracBrowser for help on using the repository browser.