source: trunk/doc/src/porting4.qdoc@ 424

Last change on this file since 424 was 2, checked in by Dmitry A. Kuminov, 17 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 164.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the documentation of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/*!
43 \page porting4.html
44 \title Porting to Qt 4
45 \contentspage {Porting Guides}{Contents}
46 \previouspage Porting Guides
47 \nextpage Porting to Qt 4 - Virtual Functions
48 \ingroup porting
49 \brief An overview of issues and techniques to consider when porting from Qt 3 to Qt 4.
50
51\omit
52 ### QFileInfo::PermissionSpec -> QFile::Permission(s?)
53 ### refer to porting4-renamedfunctions.qdoc
54 ### QApplication library mutex is gone
55 ### no integral conversion for containers? strings?
56 ### QVector etc. are initialized to 0 by default?
57 ### How to port from Qt 2.3 to Qt 4.
58 ### missing sort() functions?
59 ### QToolTipGroup
60 ### QServerSocket -> Q3ServerSocket
61
62 ### remove these when the classes are re-ported
63
64 ### QApplication::eventLoop()
65
66 \row \o void QCheckListItem::paintCell(QPainter *, const QColorGroup &, int, int, int)\row \o void Q3CheckListItem::paintCell(QPainter *, const QPalette &, int, int, int)
67 \row \o void QCheckListItem::paintFocus(QPainter *, const QColorGroup &, const QRect &) \o void Q3CheckListItem::paintFocus(QPainter *, const QPalette &, const QRect &)
68 \row \o QDataTable: a whole bunch of virtual functions have a different signature
69
70 < Function: void QIconViewItem::paintFocus(QPainter *, const QColorGroup &)
71 > Function: void QIconViewItem::paintFocus(QPainter *, const QPalette &)
72
73 < Function: void QIconViewItem::paintItem(QPainter *, const QColorGroup &)
74 > Function: void QIconViewItem::paintItem(QPainter *, const QPalette &)
75
76 < Function: bool QUrlOperator::checkValid()
77
78 < Function: void QWSInputMethod::setFont(const QFont &)
79
80 ### OpenMode or OpenMode
81
82 ### QWSDecoration
83\endomit
84
85 This document describes the process of porting applications from
86 Qt 3 to Qt 4.
87 If you haven't yet made the decision about porting, or are unsure
88 about whether it is worth it, take a look at the \l{What's New in
89 Qt 4}{key features} offered by Qt 4. See also
90 \l{Moving from Qt 3 to Qt 4} for tips on how to write Qt 3 code
91 that is easy to port to Qt 4.
92
93 \bold{Other porting guides:}
94
95 \list
96 \o \l{Moving from Qt 3 to Qt 4} \mdash covers some high level topics relevant
97 to developers porting from Qt 3 to Qt 4.
98 \o \l{Porting to Qt 4 - Drag and Drop} \mdash covers differences in the
99 way drag and drop is handled between Qt 3 and Qt 4.
100 \o \l{Porting .ui Files to Qt 4} \mdash describes the new format used to
101 describe forms created with \QD.
102 \o \l{Porting to Graphics View} \mdash provides a class-by-class overview
103 of the differences between Qt 3's canvas API and Qt 4's Graphics
104 View framework.
105 \o \l{qt3to4 - The Qt 3 to 4 Porting Tool} \mdash provides an overview
106 of a tool aimed at helping developers start the process of porting an
107 application to Qt 4.
108 \endlist
109
110 The Qt 4 series is not binary compatible with the 3 series. This
111 means programs compiled for Qt 3 must be recompiled to work with
112 Qt 4. Qt 4 is also not completely \e source compatible with 3,
113 however nearly all points of incompatibility cause compiler
114 errors or run-time messages (rather than mysterious results). Qt
115 4 includes many additional features and discards obsolete
116 functionality. Porting from Qt 3 to Qt 4 requires some effort,
117 but once completed the considerable additional power and
118 flexibility of Qt 4 is available for use in your applications.
119
120 To port code from Qt 3 to Qt 4:
121
122 \list 1
123
124 \o Briefly read the porting notes below to get an idea of what to expect.
125
126 \o Be sure that your code compiles and runs well on all your target
127 platforms with Qt 3.
128
129 \o Add the line \c{QT += qt3support} to your \c .pro file if you use
130 \c qmake; otherwise, edit your makefile or project file to
131 link against the Qt3Support library and add \c -DQT3_SUPPORT to your
132 compiler flags. (You might also need to specify other
133 libraries. See \l{What's New in Qt 4} for details.)
134
135 \o Run the \l qt3to4 porting tool. The tool will go through your
136 source code and adapt it to Qt 4.
137
138 \o Follow the instructions in the \l{Porting .ui Files to Qt 4}
139 page to port Qt Designer files.
140
141 \o Recompile with Qt 4. For each error, search below for related
142 identifiers (e.g., function names, class names). This document
143 mentions all relevant identifiers to help you get the information
144 you need at the cost of being a little verbose.
145
146 \endlist
147
148 The \l qt3to4 porting tool replaces occurrences of Qt 3 classes
149 that don't exist anymore in Qt 4 with the corresponding Qt 3
150 support class; for example, \c QListBox is turned into \c
151 Q3ListBox.
152
153 At some point, you might want to stop linking against the Qt 3
154 support library (\l{Qt3Support}) and take advantage of Qt 4's
155 new features. The instructions below explain how to do that for
156 each compatibility class.
157
158 In addition to the Qt3Support classes (such as \c Q3Action, \c
159 Q3ListBox, and \c Q3ValueList), Qt 4 provides compatibility
160 functions when it's possible for an old API to cohabit with the
161 new one. For example, QString provides a
162 QString::simplifyWhiteSpace() compatibility function that's
163 implemented inline and that simply calls QString::simplified().
164 \bold{The compatibility functions are not documented here; instead,
165 they are documented for each class.}
166
167 If you have the line \c{QT += qt3support} in your \c .pro file, \c
168 qmake will automatically define the \c QT3_SUPPORT symbol, turning
169 on compatibility function support. You can also define the symbol
170 manually (e.g., if you don't want to link against the \c
171 Qt3Support library), or you can define \c QT3_SUPPORT_WARNINGS
172 instead, telling the compiler to emit a warning when a
173 compatibility function is called. (This works only with GCC 3.2+
174 and MSVC 7.)
175
176 If you get stuck, ask on the
177 \l{http://lists.trolltech.com/qt-interest/}{qt-interest}
178 mailing list. If you are a licensed customer, you can also contact
179 Qt's technical support team.
180
181\omit
182 ### what to do with slots that aren't slots anymore
183 ### what to do with virtual functions that aren't virtual anymore
184 ### what to do with virtual functions that changed signature
185\endomit
186
187\omit
188 ### <qtl.h> -- stuff that vanished?
189 ### implicit sharing
190 ### uint -> int indexes
191\endomit
192
193 Table of contents:
194
195 \tableofcontents{4}
196
197\omit
198 \section1 Header Files
199
200 ### New style of headers
201
202 \table
203 \header \o Old header \o New header
204 \row \o \c{<qtl.h>} \o \c{<qalgorithms.h>} or \c{<QtAlgorithms>}
205 \endtable
206
207 ### Some headers don't include each other anymore...
208\endomit
209
210 \section1 Casting and Object Types
211
212 In Qt 3, it was possible to use the \c qt_cast() function to determine
213 whether instances of QObject subclasses could be safely cast to derived
214 types of those subclasses. For example, if a QFrame instance is passed
215 to a function whose signature specifies a QWidget pointer as its argument,
216 \c qt_cast() could be used to obtain a QFrame pointer so that the
217 instance's functions can be accessed.
218
219 In Qt 4, much of this functionality is provided by the qobject_cast()
220 function, and additional functions also provide similar functionality for
221 certain non-QObject types:
222
223 \table
224 \header \o Qt 3 function \o Qt 4 function
225 \row \o T *qt_cast<T *>(QObject *) \o \l{qobject_cast()}{T *qobject_cast<T *>(QObject *)}
226 \row \o \o \l{qgraphicsitem_cast()}{T qgraphicsitem_cast<T>(QGraphicsItem *)}
227 \row \o \o \l{qstyleoption_cast()}{T qstyleoption_cast<T>(QStyleOption *)}
228 \row \o \o \l{qvariant_cast()}{T qvariant_cast<T>(const QVariant &)}
229 \row \o \o \l{qdbus_cast()}{T qdbus_cast(const QDBusArgument &)}
230 \endtable
231
232\omit
233 \section1 Global Functions
234
235 \table
236 \header \o Qt 3 function \o Qt 4 function
237 \row \o cstrcmp() \o strcmp()
238 \row \o cstrcpy() \o strcpy()
239 \row \o cstrlen() \o strlen()
240 \row \o cstrncmp() \o strncmp()
241 \row \o qmemmove() \o memmove()
242 \endtable
243
244 qGLVersion() ###
245
246 copyBlt() ###
247 bitBlt()
248
249 #ifdef compat classes:
250 * QLayoutIterator
251 * QColorGroup
252 * QMenuItem
253
254 QWidget visibleRect property compat
255 QWidget::BackgroundOrigin compat
256\endomit
257
258 \section1 Type Names
259
260 The table below lists the classes that have been renamed in Qt 4.
261 If you compile your applications with \c QT3_SUPPORT defined, the
262 old names will be available.
263
264 Whenever you see an occurrence of the name on the left, you can
265 safely replace it with the Qt 4 equivalent in your program. The
266 \l qt3to4 tool performs the conversion automatically.
267
268 \table
269 \header \o Qt 3 class name \o Qt 4 class name
270 \input porting4-renamedclasses.qdocinc
271 \endtable
272
273 The table below lists the enums and typedefs that have been
274 renamed in Qt 4. If you compile your applications with \c
275 QT3_SUPPORT defined, the old names will be available.
276
277 Whenever you see an occurrence of the name on the left, you can
278 safely replace it with the Qt 4 equivalent in your program. The
279 \l qt3to4 tool performs the conversion
280 automatically.
281
282 \table
283 \header \o Qt 3 type name \o Qt 4 type name
284 \input porting4-renamedtypes.qdocinc
285 \endtable
286
287 \omit
288 ###
289 \row \o QButton::ToggleState \o Use QCheckBox::ToggleState instead.
290 \endomit
291
292 \section1 Enum Values
293
294 The table below lists the enum values that have been renamed in
295 Qt 4. If you compile your applications with \c QT3_SUPPORT defined,
296 the old names will be available.
297
298 Whenever you see an occurrence of the name on the left, you can
299 safely replace it with the Qt 4 equivalent in your program. The
300 \l qt3to4 tool performs the conversion automatically.
301
302 \table
303 \header \o Qt 3 enum value name \o Qt 4 enum value name
304 \input porting4-renamedenumvalues.qdocinc
305 \endtable
306
307 In addition, the following \l{Qt::WindowFlags}{window flags} have
308 been either replaced with \l{Qt::WidgetAttribute}{widget
309 attributes} or have been deprecated:
310
311 \table
312 \header \o Qt 3 type \o Qt 4 equivalent
313 \row \o Qt::WDestructiveClose \o Use QWidget::setAttribute(Qt::WA_DeleteOnClose) instead.
314 \row \o Qt::WStaticContents \o{1,2} Use QWidget::setAttribute(Qt::WA_StaticContents) instead.
315 \row \o Qt::WNorthWestGravity
316 \row \o Qt::WNoAutoErase \o{1,3} Use QWidget::setAttribute(Qt::WA_NoBackground) instead.
317 \row \o Qt::WResizeNoErase
318 \row \o Qt::WRepaintNoErase
319 \row \o Qt::WPaintClever \o Unnecessary in Qt 4.
320 \omit ### Check with Matthias \endomit
321 \row \o Qt::WMacNoSheet \o Unnecessary in Qt 4.
322 \omit ### Check with Sam \endomit
323 \endtable
324
325 In Qt 4.1, the widget flags used to determine window modality were
326 replaced by a single enum that can be used to specify the modal
327 behavior of top-level widgets:
328
329 \table
330 \header \o Qt 3 type \o Qt 4 equivalent
331 \row \o Qt::WShowModal \o Use QWidget::setWindowModality(Qt::ApplicationModal) instead.
332 \row \o Qt::WGroupLeader \o Use QWidget::setWindowModality(Qt::WindowModal)
333 for each child dialog of the group leader, but do not change the modality
334 of the group leader itself.
335 \endtable
336
337 \target properties
338 \section1 Properties
339
340 Some properties have been renamed in Qt 4, to make Qt's API more
341 consistent and more intuitive. For example, QWidget's \c caption
342 property has been renamed \c windowTitle to make it clear that it
343 refers to the title shown in the window's title bar.
344
345 In addition, the property system has been extended to allow
346 properties to be redefined in subclasses with the \l Q_PROPERTY()
347 macro, removing the need for a \c Q_OVERRIDE() macro.
348
349 The table below lists the Qt properties that have been renamed in
350 Qt 4. Occurrences of these in \e{Qt Designer} \c .ui files are
351 automatically converted to the new name by \c uic.
352
353 \table
354 \header \o Qt 3 name \o Qt 4 name
355 \row \o QButton::accel \o QButton::shortcut
356 \row \o QButton::on \o QButton::checked
357 \row \o QButton::toggleButton \o QAbstractButton::checkable
358 \row \o QDial::lineStep \o QDial::singleStep
359 \row \o QDial::maxValue \o QDial::maximum
360 \row \o QDial::minValue \o QDial::minimum
361 \row \o QDialog::modal \o QDialog::isModal
362 \row \o QLineEdit::edited \o QLineEdit::modified
363 \row \o QLineEdit::hasMarkedText \o QLineEdit::hasSelectedText
364 \row \o QLineEdit::markedText \o QLineEdit::selectedText
365 \row \o QObject::name \o QObject::objectName
366 \row \o QProgressDialog::progress \o QProgressDialog::value
367 \row \o QProgressDialog::totalSteps \o QProgressDialog::maximum
368 \row \o QProgressDialog::wasCancelled \o QProgressDialog::wasCanceled
369 \row \o QPushButton::iconSet \o QPushButton::icon
370 \row \o QScrollBar::draggingSlider \o QScrollBar::sliderDown
371 \row \o QScrollBar::lineStep \o QScrollBar::singleStep
372 \row \o QScrollBar::maxValue \o QScrollBar::maximum
373 \row \o QScrollBar::minValue \o QScrollBar::minimum
374 \row \o QSlider::lineStep \o QSlider::singleStep
375 \row \o QSlider::maxValue \o QSlider::maximum
376 \row \o QSlider::minValue \o QSlider::minimum
377 \row \o QSpinBox::lineStep \o QSpinBox::singleStep
378 \row \o QSpinBox::maxValue \o QSpinBox::maximum
379 \row \o QSpinBox::minValue \o QSpinBox::minimum
380 \row \o QTabBar::currentTab \o QTabBar::currentIndex
381 \row \o QTabWidget::currentPage \o QTabWidget::currentWidget
382 \row \o QToolButton::iconSet \o QToolButton::icon
383 \row \o QToolButton::textLabel \o QToolButton::text
384 \row \o QWidget::caption \o QWidget::windowTitle
385 \row \o QWidget::icon \o QWidget::windowIcon
386 \row \o QWidget::iconText \o QWidget::windowIconText
387 \endtable
388
389 A handful of properties in Qt 3 are no longer properties in Qt 4,
390 but the access functions still exist as part of the Qt 4 API.
391 These are not used by \e{Qt Designer}; the only case where you
392 need to worry about them is in highly dynamic applications that
393 use Qt's meta-object system to access properties. Here's the list
394 of these properties with the read and write functions that you
395 can use instead:
396
397 \table
398 \header \o Qt 3 property \o Qt 4 read function \o Qt 4 write function
399 \row \o QSqlDatabase::connectOptions \o QSqlDatabase::connectOptions() \o QSqlDatabase::setConnectOptions()
400 \row \o QSqlDatabase::databaseName \o QSqlDatabase::databaseName() \o QSqlDatabase::setDatabaseName()
401 \row \o QSqlDatabase::hostName \o QSqlDatabase::hostName() \o QSqlDatabase::setHostName()
402 \row \o QSqlDatabase::password \o QSqlDatabase::password() \o QSqlDatabase::setPassword()
403 \row \o QSqlDatabase::port \o QSqlDatabase::port() \o QSqlDatabase::setPort()
404 \row \o QSqlDatabase::userName \o QSqlDatabase::userName() \o QSqlDatabase::setUserName()
405 \endtable
406
407 Some properties have been removed from Qt 4, but the associated
408 access functions are provided if \c QT3_SUPPORT is defined to help
409 porting to Qt 4. When converting Qt 3 \c .ui files to Qt 4, \c uic
410 generates calls to the Qt 3 compatibility functions. Note that
411 this only applies to the properties of the Qt3Support library,
412 i.e. \c QT3_SUPPORT properties of the other libraries must be
413 ported manually when converting Qt 3 .ui files to Qt 4.
414
415 The table below lists these properties with the read and write
416 functions that you can use instead. The documentation for the
417 individual functions explains how to replace them with
418 non-compatibility Qt 4 functions.
419
420 \table
421 \header \o Qt 3 property \o Qt 4 read function (\c QT3_SUPPORT)\o Qt 4 write function (\c QT3_SUPPORT)
422 \row \o QMenuBar::separator \o QMenuBar::separator() \o QMenuBar::setSeparator()
423 \row \o QPushButton::menuButton \o QPushButton::isMenuButton() \o N/A
424 \row \o QTabWidget::margin \o QTabWidget::margin() \o QTabWidget::setMargin()
425 \row \o QTextEdit::textFormat \o QTextEdit::textFormat() \o QTextEdit::setTextFormat()
426 \row \o QWidget::backgroundBrush \o QWidget::backgroundBrush() \o N/A
427 \row \o QWidget::backgroundMode \o QWidget::backgroundMode() \o QWidget::setBackgroundMode()
428 \row \o QWidget::backgroundOrigin \o QWidget::backgroundOrigin() \o QWidget::setBackgroundOrigin()
429 \row \o QWidget::colorGroup \o QWidget::colorGroup() \o QWidget::setColorGroup()