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

Last change on this file since 109 was 2, checked in by Dmitry A. Kuminov, 16 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()
430 \row \o QWidget::customWhatsThis \o QWidget::customWhatsThis() \o QWidget::setCustomWhatsThis()
431 \row \o QWidget::inputMethodEnabled \o QWidget::inputMethodEnabled() \o QWidget::setInputMethodEnabled()
432 \row \o QWidget::ownCursor \o QWidget::ownCursor() \o N/A
433 \row \o QWidget::ownFont \o QWidget::ownFont() \o N/A
434 \row \o QWidget::ownPalette \o QWidget::ownPalette() \o N/A
435 \row \o QWidget::paletteBackgroundColor \o QWidget::paletteBackgroundColor() \o QWidget::setPaletteBackgroundColor()
436 \row \o QWidget::paletteBackgroundPixmap \o QWidget::paletteBackgroundPixmap() \o QWidget::setPaletteBackgroundPixmap()
437 \row \o QWidget::paletteForegroundColor \o QWidget::paletteForegroundColor() \o QWidget::setPaletteForegroundColor()
438 \row \o QWidget::underMouse \o QWidget::underMouse() \o N/A
439 \endtable
440
441 The following Qt 3 properties and their access functions are no
442 longer available in Qt 4. In most cases, Qt 4 provides similar
443 functionality.
444
445 \table
446 \header \o Qt 3 property \o Qt 4 equivalent
447 \row \o QButton::autoRepeat \o N/A
448 \row \o QButton::autoResize \o Call QWidget:setFixedSize(QWidget::sizeHint()) whenever you change the contents.
449 \row \o QButton::exclusiveToggle \o See \l QAbstractButton::autoExclusive.
450 \row \o QButton::pixmap \o Use QAbstractButton::icon instead.
451 \row \o QButton::toggleState \o Use QCheckBox::setState() and QCheckBox::state() instead.
452 \row \o QButton::toggleType \o Use QCheckBox::setTristate() instead.
453 \row \o QComboBox::autoResize \o Call QWidget:setFixedSize(QWidget::sizeHint()) whenever you change the contents.
454 \row \o QFrame::contentsRect \o Use Q3Frame::contentsRect() instead.
455 \row \o QFrame::margin \o Use QWidget::setContentsMargins() instead.
456 \row \o QTabBar::keyboardFocusTab \o N/A
457 \row \o QToolButton::offIconSet \o Use the \l{QIcon::Off}{off component} of QAbstractButton::icon instead.
458 \row \o QToolButton::onIconSet \o Use the \l{QIcon::On}{on component} of QAbstractButton::icon instead.
459 \row \o QWidget::microFocusHint \o N/A
460 \endtable
461
462\omit
463 \section1 Inheritance Chain
464
465 ### QMenuBar, etc.
466
467 \section1 Null vs. Empty
468
469 ###
470\endomit
471
472 \section1 Explicit Sharing
473
474 Qt 4 is the first version of Qt that contains no \link
475 http://doc.trolltech.com/3.3/shclass.html explicitly shared
476 \endlink classes. All classes that were explicitly shared in Qt 3
477 are \e implicitly shared in Qt 4:
478
479 \list
480 \o QImage
481 \o QBitArray
482 \o QByteArray
483 \o Q3PointArray
484 \endlist
485
486 This means that if you took a copy of an instance of the class
487 (using operator=() or the class's copy constructor), any
488 modification to the copy would affect the original and vice
489 versa. Needless to say, this behavior is rarely desirable.
490
491 Fortunately, nearly all Qt 3 applications don't rely on explicit
492 sharing. When porting, you typically only need to remove calls to
493 detach() and/or copy(), which aren't necessary anymore.
494
495 If you deliberately rely on explicit sharing in your application,
496 you can use pointers or references to achieve the same result in
497 Qt 4.
498
499 \oldcode
500 void asciify(QByteArray array)
501 {
502 for (int i = 0; i < (int)array.size(); ++i) {
503 if ((uchar)array[i] >= 128)
504 array[i] = '?';
505 }
506 }
507 \newcode
508 void asciify(QByteArray &array)
509 {
510 for (int i = 0; i < array.size(); ++i) {
511 if ((uchar)array[i] >= 128)
512 array[i] = '?';
513 }
514 }
515 \endcode
516
517 (Notice the \c & in the parameter declaration.)
518
519\omit
520 \section1 Qt Designer .ui Files
521
522 ###
523\endomit
524
525 \section1 Painting and Redrawing Widgets
526
527 When implementing custom widgets in Qt 3, it was possible to use
528 QPainter to draw on a widget outside paint events. This made it
529 possible to integrate Qt applications with third party libraries
530 and tools that impose their own rendering models. For example,
531 a widget might be repainted in a slot using data obtained from
532 an external source.
533
534 In Qt 4, it is only possible to paint on a widget from within its
535 \l{QWidget::}{paintEvent()} handler function. This restriction simplifies
536 Qt's interaction with native window systems, improves the performance
537 of applications by reducing the number of redraw operations, and
538 also enables features to be implemented to improve the appearance of
539 widgets, such as a backing store.
540
541 Generally, we recommend redesigning applications to perform all
542 painting operations in \l{QWidget::}{paintEvent()} functions, deferring
543 actual painting until the next time this function is called.
544 Applications can post paint events to trigger repaints, and it may be
545 possible to examine your widget's internal state to determine which
546 part of the widget needs to be repainted.
547
548 If asynchronous repaints are used extensively by your application,
549 and it is not practical to redesign the rendering model to perform
550 all painting operations from within a widget's \l{QWidget::}{paintEvent()}
551 function, it may be necessary to consider using an intermediate painting
552 step. In this approach, one or more images can be updated asynchronously
553 and painted on the widget in the paint event. To avoid excessive
554 buffering, it may be worthwhile disabling the backing store by setting
555 the widget's Qt::WA_PaintOnScreen widget attribute.
556
557 On certain platforms, the Qt::WA_PaintOutsidePaintEvent widget attribute
558 can be set to allow a widget to be painted from outside paint events.
559
560 \note Setting widget attributes to disable key features of Qt's widget
561 rendering model may also cause other features to be disabled.
562
563 \section1 QAccel
564
565 The \c QAccel class has been renamed Q3Accel and moved to the
566 Qt3Support module. In new applications, you have three options:
567
568 \list 1
569 \o You can use QAction and set a key sequence using QAction::setShortcut().
570 \o You can use QShortcut, a class that provides similar
571 functionality to Q3Accel.
572 \o You can use QWidget::grabShortcut() and process "shortcut"
573 events by reimplementing QWidget::event().
574 \endlist
575
576 The Q3Accel class also supports multiple accelerators using the
577 same object, by calling Q3Accel::insertItem() multiple times. In
578 Qt 4, the solution is to create multiple QShortcut objects.
579
580 \section1 QAccessibleInterface
581
582 The QAccessibleInterface class has undergone some API changes in
583 Qt 4, to make it more consistent with the rest of the Qt API.
584
585 If you have classes that inherit QAccessibleInterface or one of
586 its subclasses (QAccessibleObject, QAccessibleWidget, etc.), you
587 must port them the new QAccessibleInterface API.
588
589 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions}
590 for a list of QAccessibleInterface virtual member functions in
591 Qt 3 that are no longer virtual in Qt 4.
592
593 \section1 QAccessibleTitleBar
594
595 The \c QAccessibleTitleBar has been renamed Q3AccessibleTitleBar
596 and moved to the Qt3Support library.
597
598 \target qaction.section
599 \section1 QAction
600
601 The QAction class has been redesigned in Qt 4 to integrate better
602 with the rest of the menu system. It unifies the old \c QMenuItem
603 class and the old \c QAction class into one class, avoiding
604 unnecessary data duplication and the need to learn two different
605 APIs.
606
607 The old \c QAction and \c QActionGroup classes have been renamed
608 Q3Action and Q3ActionGroup and moved to Qt3Support. In addition,
609 the new QAction class has compatibility functions to ease
610 transition to Qt 4. Note that when using Q3ToolBar and
611 Q3PopupMenu, their actions must be \l {Q3Action}s.
612
613 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions}
614 for a list of QAction virtual member functions in Qt 3 that are
615 no longer virtual in Qt 4.
616
617 \section1 QActionGroup
618
619 The QAction class has been completely redesigned in Qt 4 to
620 integrate better with the rest of the menu system. See the
621 \l{#qaction.section}{section on QAction} for details.
622
623 \section1 QApplication
624
625 The QApplication class has been split into two classes:
626 QCoreApplication and QApplication. The new QApplication class
627 inherits QCoreApplication and adds GUI-related functionality. In
628 practice, this has no consequences for existing Qt applications.
629
630 In addition, the following API changes were made:
631
632 \list 1
633 \o QApplication::allWidgets() and QApplication::topLevelWidgets()
634 used to return a pointer to a QWidgetList. Now they return a
635 QWidgetList.
636
637 Also, QWidgetList has changed from being a typedef for
638 QPtrList<QWidget> to being a typedef for QList<QWidget *>.
639 See the \l{#qwidgetlist.section}{section on QWidgetList} below
640 for details.
641
642 \oldcode
643 QWidgetList *list = QApplication::topLevelWidgets();
644 QWidgetListIt it(*list);
645 QWidget *widget;
646 while ((widget = it.current())) {
647 if (widget->inherits("MainWindow"))
648 ((MainWindow *)widget)->updateRecentFileItems();
649 ++it;
650 }
651 delete list;
652 \newcode
653 QWidgetList list = QApplication::topLevelWidgets();
654 for (int i = 0; i < list.size(); ++i) {
655 if (MainWindow *mainWin = qobject_cast<MainWindow *>(list.at(i)))
656 mainWin->updateRecentFileItems();
657 }
658 \endcode
659 \o QApplication::setMainWidget() is no longer used. When all an application's
660 windows are closed, the application will exit normally.
661 \endlist
662
663 \section1 QAquaStyle
664
665 The \c QAquaStyle class first appeared in Qt 3.0, when the Qt for
666 Mac OS X port was first released. It emulated Apple's "Aqua" theme.
667 In Qt 3.1, QAquaStyle was obsoleted by QMacStyle, which uses Appearance
668 Manager to perform its drawing.
669
670 The \c QAquaStyle class is no longer provided in Qt 4. Use
671 QMacStyle instead.
672
673 \target qasciidict.section
674 \section1 QAsciiCache<T>
675
676 \c QAsciiCache<T> has been renamed Q3AsciiCache<T> and moved to
677 the Qt3Support library. It has been replaced by
678 QCache<QByteArray, T>.
679
680 For details, read the \l{#qcache.section}{section on QCache<T>},
681 mentally substituting QByteArray for QString.
682
683 \section1 QAsciiDict<T>
684
685 QAsciiDict<T> and QAsciiDictIterator<T> have been renamed
686 Q3AsciiDict<T> and Q3AsciiDictIterator<T> and moved to the
687 Qt3Support library. They have been replaced by the
688 more modern QHash<Key, T> and QMultiHash<Key, T> classes and
689 their associated iterator classes.
690
691 When porting old code that uses Q3AsciiDict<T> to Qt 4, there are
692 four classes that you can use:
693
694 \list
695 \o QMultiHash<QByteArray, T *>
696 \o QMultiHash<QByteArray, T>
697 \o QHash<QByteArray, T *>
698 \o QHash<QByteArray, T>
699 \endlist
700
701 For details, read the \l{#qdict.section}{section on QDict<T>},
702 mentally substituting QByteArray for QString.
703
704 \section1 QAsyncIO
705
706 The \c QAsyncIO class was used internally in Qt 2.x in
707 conjunction with QImageConsumer. It was obsoleted in Qt 3.0.
708
709 \input porting4-obsoletedmechanism.qdocinc
710
711 \section1 QBackInsertIterator
712
713 The undocumented \c QBackInsertIterator class has been removed
714 from the Qt library. If you need it in your application, feel
715 free to copy the source code from the Qt 3 \c <qtl.h> header
716 file.
717
718 \section1 QBitArray
719
720 In Qt 3, QBitArray inherited from QByteArray. In Qt 4, QBitArray
721 is a totally independent class. This makes very little difference
722 to the user, except that the new QBitArray doesn't provide any of
723 QByteArray's byte-based API anymore. These calls will result in a
724 compile-time error, except calls to QBitArray::truncate(), whose
725 parameter was a number of \e bytes in Qt 3 and a number of bits
726 in Qt 4.
727
728 QBitArray was an explicitly shared class in Qt 3. See \l{Explicit
729 Sharing} for more information.
730
731 The \c QBitVal class has been renamed QBitRef.
732
733 \section1 QButton
734
735 The \c QButton class has been replaced by QAbstractButton in Qt
736 4. Classes like QPushButton and QRadioButton inherit from
737 QAbstractButton. As a help when porting older Qt applications,
738 the Qt3Support library contains a Q3Button class
739 implemented in terms of the new QAbstractButton.
740
741 If you used the \c QButton class as a base class for your own
742 button type and want to port your code to the newer
743 QAbstractButton, you need to be aware that QAbstractButton has no
744 equivalent for the Q3Button::drawButton(QPainter *) virtual
745 function. The solution is to reimplement QWidget::paintEvent() in
746 your QAbstractButton subclass as follows:
747
748 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 0
749
750 \table
751 \header \o Q3Button function \o QAbstractButton equivalent
752 \row \o Q3Button::autoResize() \o Call QWidget:setFixedSize(QWidget::sizeHint()) whenever you change the contents.
753 \row \o Q3Button::isExclusiveToggle() \o Use QAbstractButton::group() or QAbstractButton::autoExclusive() instead.
754 \row \o Q3Button::pixmap() const \o QAbstractButton::icon()
755 \row \o Q3Button::setAutoResize() \o N/A
756 \row \o Q3Button::setPixmap(const QPixmap &) \o QAbstractButton::setIcon(const QIcon &)
757 \row \o Q3Button::setState(ToggleState) \o See remark below
758 \row \o Q3Button::setToggleType(ToggleType) \o See remark below
759 \row \o Q3Button::state() \o See remark below
760 \row \o Q3Button::stateChanged(int) \o See remark below
761 \row \o Q3Button::toggleType() \o See remark below
762 \endtable
763
764 Remarks:
765
766 \list 1
767 \o In Qt 3, \c QButton had a "toggle type", which could be
768 QButton::SingleShot, QButton::Toggle, or QButton::Tristate.
769 The new QAbstractButton class doesn't support "tristate"
770 directly; this feature is implemented in QCheckBox instead.
771 The two other "toggle types" (\c QButton::SingleShot and \c
772 QButton::Toggle) are replaced by a QAbstractButton::checkable
773 property.
774 \o In Qt 3, QButton had a "toggle state", which could be \c
775 QButton::Off, \c QButton::NoChange, or \c QButton::On. In Qt
776 4, this mechanism has been moved to QCheckBox.
777 \endlist
778
779 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions} for
780 a list of \c QButton virtual member functions in Qt 3 that aren't
781 virtual in Qt 4.
782
783 See \l{#properties}{Properties} for a list of \c QButton properties
784 in Qt 3 that have changed in Qt 4.
785
786 \section1 QButtonGroup
787
788 The \c QButtonGroup class has been completely redesigned in Qt 4.
789 For compatibility, the old \c QButtonGroup class has been renamed
790 Q3ButtonGroup and has been moved to Qt3Support.
791 Likewise, the \c QHButtonGroup and \c QVButtonGroup convenience
792 subclasses have been renamed \c Q3HButtonGroup and \c Q3VButtonGroup and
793 moved to the Qt3Support library.
794
795 The old \c QButtonGroup, as well as Q3ButtonGroup, can be used in two ways:
796
797 \list 1
798 \o The button group is the parent widget of a number of buttons,
799 i.e. the button group is the parent argument in the button
800 constructor. The buttons are assigned identifiers 0, 1, 2, etc.,
801 in the order they are created. A Q3ButtonGroup can display a frame
802 and a title because it inherits Q3GroupBox.
803 \o The button group is an invisible widget and the contained
804 buttons have some other parent widget. In this usage, each
805 button must be manually inserted, using
806 Q3ButtonGroup::insert(), into the button group and given an
807 ID number.
808 \endlist
809
810 Unlike Q3ButtonGroup, the new QButtonGroup doesn't inherit
811 QWidget. It is very similar to a "hidden Q3ButtonGroup".
812
813 If you use a Q3ButtonGroup, Q3HButtonGroup, or Q3VButtonGroup as
814 a widget and want to port to Qt 4, you can replace it with
815 QGroupBox. In Qt 4, radio buttons with the same parent are
816 automatically part of an exclusive group, so you normally don't
817 need to do anything else. See also the
818 \l{#qgroupbox.section}{section on QGroupBox} below.
819
820 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions} for
821 a list of QButtonGroup virtual member functions in Qt 3 that are no
822 longer virtual in Qt 4.
823
824 \target qbytearray.section
825 \section1 QByteArray
826
827 In Qt 3, QByteArray was simply a typedef for QMemArray<char>. In
828 Qt 4, QByteArray is a class in its own right, with a higher-level
829 API in the style of QString.
830
831 Here are the main issues to be aware of when porting to Qt 4:
832
833 \list 1
834 \o The QMemArray(int size) constructor has been replaced with
835 QByteArray(int size, char ch). The second argument specifies
836 which character should be used for initializing the array;
837 pass '\\0' if you have no specific needs.
838
839 \oldcode
840 QByteArray ba(64);
841 \newcode
842 QByteArray ba(64, '\0');
843 \endcode
844
845 \o QMemArray::at() returned a non-const reference, whereas the
846 new QByteArray::at() returns a const value. Code like
847
848 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 1
849
850 will no longer compile. Instead, use QByteArray::operator[]:
851
852 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 2
853
854 \o The QMemArray::contains(char) function has been renamed
855 QByteArray::count(char). In addition, there now exists a
856 QByteArray::contains(char) function that returns a boolean
857 value. Replace old calls to contains() with either count() or
858 contains(), depending on whether you care about the specific
859 number of occurrences of a character in the byte array or
860 only care about whether the array contains that character or
861 not.
862
863 \o The new QByteArray has no assign() function. Calls to
864 QMemArray::assign(const QMemArray &) can be replaced by calls
865 to QByteArray::operator=(). Calls to QMemArray::assign(const
866 T *, uint) have no equivalent in Qt 4; if you use it, the
867 solution is either to use QByteArray::fromRawData() and to
868 call free() yourself to avoid a memory leak, or to use the
869 QByteArray(const char *, int) constructor, which will take a
870 deep copy of the data.
871
872 \o QMemArray::bsearch() and QMemArray::sort() have no equivalent
873 in the new QByteArray class. Use \l qBinaryFind() and \l qSort()
874 if you need that functionality.
875 \endlist
876
877 QByteArray was an explicitly shared class in Qt 3. See
878 \l{Explicit Sharing} for more information.
879
880 \target qcache.section
881 \section1 QCache<T>
882
883 QCache<T> has been renamed Q3Cache<T> and moved to Qt3Support.
884 The new QCache class has a different API, and takes different
885 template parameters: QCache<Key, T>.
886
887 When porting to Qt 4, QCache<QString, T> is the obvious
888 substitute for Q3Cache<T>. The following table summarizes the API
889 differences.
890
891 \table
892 \header \o Q3Cache<T> function \o QCache<QString, T> equivalent
893 \row \o Q3Cache::Q3Cache(int maxCost, int size, bool caseSensitive) \o See remark below
894 \row \o Q3Cache::autoDelete() \o N/A
895 \row \o Q3Cache::count() \o QCache::count() or QCache::size() (equivalent)
896 \row \o Q3Cache::setAutoDelete() \o See remark below
897 \row \o Q3Cache::size() \o N/A
898 \row \o Q3Cache::statistics() \o N/A
899 \row \o Q3Cache::operator=() \o See remark below
900 \endtable
901
902 Remarks:
903
904 \list 1
905 \o Q3Cache requires the user to allocate a specific number of
906 buckets by passing a prime number (17 by default) to the
907 constructor. In contrast, the new QCache's hash table
908 automatically grows and shrinks as needed, and the
909 constructor doesn't take a prime number.
910
911 \o Q3Cache supportes case-insensitive lookups by passing false as
912 second argument to the constructor. This feature has no
913 equivalent in QMultiHash. Instead, call QString::toLower()
914 before you insert or lookup a key in the hash.
915
916 \o The Q3Cache::insert() function returns a \c bool value that
917 indicates whether or not the item actually was inserted in
918 the cache. If the item wasn't inserted, it was the caller's
919 responsibility to delete the item. The new QCache::insert()
920 function returns \c void and either adds it to the cache or
921 deletes it right away. Old code like
922
923 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 3
924
925 becomes
926
927 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 4
928
929 \o The new QCache class \e always takes ownership of the items
930 it stores (i.e. auto-delete is always on). If you use Q3Cache
931 with auto-delete turned off (the rarely useful default), you
932 cannot use QCache as a direct substitute. One unelegant trick
933 that works well in practice is to use QCache<QString, T *>
934 instead of QCache<QString, T>. In that case, QCache owns the
935 pointers, not the objects that the pointers refer to. For
936 example,
937
938 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 5
939
940 becomes
941
942 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 6
943
944 An alternative is to stick to using Q3Cache.
945 \endlist
946
947 QCacheIterator<T> has been renamed Q3CacheIterator<T> and moved
948 to the Qt3Support library. The new QCache class
949 doesn't offer any iterator types.
950
951 \section1 QCanvas
952
953 The canvas module classes have been
954 renamed and moved to the Qt3Support library.
955
956 \table
957 \header \o Qt 3 class name \o Compatibility class in Qt 4
958 \row \o \c QCanvas \o Q3Canvas
959 \row \o \c QCanvasEllipse \o Q3CanvasEllipse
960 \row \o \c QCanvasItem \o Q3CanvasItem
961 \row \o \c QCanvasItemList \o Q3CanvasItemList
962 \row \o \c QCanvasLine \o Q3CanvasLine
963 \row \o \c QCanvasPixmap \o Q3CanvasPixmap
964 \row \o \c QCanvasPixmapArray \o Q3CanvasPixmapArray
965 \row \o \c QCanvasPolygon \o Q3CanvasPolygon
966 \row \o \c QCanvasPolygonalItem \o Q3CanvasPolygonalItem
967 \row \o \c QCanvasRectangle \o Q3CanvasRectangle
968 \row \o \c QCanvasSpline \o Q3CanvasSpline
969 \row \o \c QCanvasSprite \o Q3CanvasSprite
970 \row \o \c QCanvasText \o Q3CanvasText
971 \row \o \c QCanvasView \o Q3CanvasView
972 \endtable
973
974 \l{The Graphics View Framework} replaces QCanvas. For more on porting to
975 Graphics View, see \l{Porting to Graphics View}.
976
977 \section1 QColor
978
979 In Qt 4, QColor is a value type like QPoint or QRect. Graphics
980 system-specific code has been implemented in QColormap.
981
982 The \c QColor::maxColors() function has been replaced
983 by QColormap::size().
984
985 The \c QColor::numBitPlanes() function has been replaced
986 by QColormap::depth().
987
988 The \c QColor::setNamedColor() function no longer supports
989 the named color in the same way as Qt 3. Qt 4's
990 \l{QColor::}{setNamedColor()} uses the new W3C convention
991 as stated
992 \l{http://www.w3.org/TR/SVG/types.html#ColorKeywords}{here}.
993
994 \table
995 \header \o{4,1} Predefined Qt Colors
996 \row \o Qt::color0 \o Qt::color1 \o Qt::black \o Qt::white
997 \row \o Qt::darkGray \o Qt::gray \o Qt::lightGray \o Qt::red
998 \row \o Qt::green \o Qt::blue \o Qt::cyan \o Qt::magenta
999 \row \o Qt::yellow \o Qt::darkRed \o Qt::darkGreen \o Qt::darkBlue
1000 \row \o Qt::darkCyan \o Qt::darkMagenta \o Qt::darkYellow \o Qt::transparent
1001 \endtable
1002
1003 The predefined colors listed in the table above were static
1004 QColor objects in Qt 3. In Qt 4, they are enum values of type
1005 Qt::GlobalColor. Thanks to the implicit QColor(Qt::GlobalColor)
1006 constructor, the enum values are automatically converted to
1007 \l{QColor}s in most contexts. Occasionally, you might need a
1008 cast.
1009
1010 \oldcode
1011 QColor lightCyan = Qt::cyan.light(180);
1012 \newcode
1013 QColor lightCyan = QColor(Qt::cyan).light(180);
1014 \endcode
1015
1016 \section1 QColorGroup
1017
1018 In Qt 3, a QPalette consisted of three QColorGroup objects. In Qt
1019 4, the (rarely used) QColorGroup abstraction has been eliminated.
1020 For source compatibility, a QColorGroup class is available when
1021 \c QT3_SUPPORT is defined.
1022
1023 The new QPalette still works in terms of color groups, specified
1024 through enum values (QPalette::Active, QPalette::Disabled, and
1025 QPalette::Inactive). It also has the concept of a \e current
1026 color group, which you can set using
1027 QPalette::setCurrentColorGroup().
1028
1029 The QPalette object returned by QWidget::palette() returns a
1030 QPalette initialized with the correct current color group for the
1031 widget. This means that if you had code like
1032
1033 \badcode
1034 painter.setBrush(colorGroup().brush(QColorGroup::Text));
1035 \endcode
1036
1037 you can simply replace colorGroup() with palette():
1038
1039 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 7
1040
1041 \section1 QColorDrag
1042
1043 The \c QColorDrag class has been renamed Q3ColorDrag and moved to
1044 the Qt3Support library. In Qt 4, use QMimeData
1045 instead and call QMimeData::setColor() to set the color.
1046
1047 \section1 QComboBox
1048
1049 In Qt 3, the list box used to display the contents of a \c QComboBox
1050 widget could be accessed by using the \c listBox() function. In Qt 4,
1051 the standard list box is provided by a QListView widget, and can be
1052 accessed with the \l{QComboBox::view()}{view()} function.
1053
1054 \omit ### \endomit
1055
1056 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions} for
1057 a list of QComboBox virtual member functions in Qt 3 that are no longer
1058 virtual in Qt 4.
1059
1060 \section1 QCString
1061
1062 In Qt 3, QCString inherited from QByteArray. The main drawback
1063 of this approach is that the user had the responsibility of
1064 ensuring that the string is '\\0'-terminated. Another important
1065 issue was that conversions between \c QCString and QByteArray often
1066 gave confusing results. (See the
1067 \l{http://doc.trolltech.com/qq/qq05-achtung.html#qcstringisastringofchars}{Achtung!
1068 Binary and Character Data} article in \e{Qt Quarterly} for an
1069 overview of the pitfalls.)
1070
1071 Qt 4 solves that problem by merging the QByteArray and \c QCString
1072 classes into one class called QByteArray. Most functions that
1073 were in \c QCString previously have been moved to QByteArray. The
1074 '\\0' issue is handled by having QByteArray allocate one extra
1075 byte that it always sets to '\\0'. For example:
1076
1077 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 8
1078
1079 The Qt3Support library contains a class called
1080 Q3CString that inherits from the new QByteArray class and that
1081 extends it to provide an API that is as close to the old \c QCString
1082 class as possible. Note that the following functions aren't
1083 provided by Q3CString:
1084
1085 \list
1086 \o QCString::find(const QRegExp &, int)
1087 \o QCString::findRev(const QRegExp &, int)
1088 \o QCString::contains(const QRegExp &)
1089 \o QCString::replace(const QRegExp &, const char *)
1090 \endlist
1091
1092 The following functions have lost their last parameter, which
1093 specified whether the search was case sensitive or not:
1094
1095 \list
1096 \o QByteArray::find(char, int)
1097 \o QByteArray::find(const char *, int)
1098 \o QByteArray::findRev(char, int)
1099 \o QByteArray::findRev(const char *, int)
1100 \o QByteArray::contains(char)
1101 \o QByteArray::contains(const char *)
1102 \endlist
1103
1104 In both cases, the solution is to convert the \c QCString to a
1105 QString and use the corresponding QString functions instead.
1106
1107 Also be aware that \c QCString::size() (inherited from
1108 QByteArray) used to return the size of the character data \e
1109 including the '\\0'-terminator, whereas the new
1110 QByteArray::size() is just a synonym for QByteArray::length().
1111 This brings QByteArray in line with QString.
1112
1113 When porting to Qt 4, occurrences of \c QCString should be
1114 replaced with QByteArray or QString. The following table
1115 summarizes the API differences between the Q3CString
1116 class and the Qt 4 QByteArray and QString classes:
1117
1118 \table
1119 \header \o Q3CString function \o Qt 4 equivalent
1120 \row \o Q3CString::Q3CString(const char *, uint) \o See remark below
1121 \row \o Q3CString::Q3CString(int) \o QByteArray::QByteArray(int, char)
1122 \row \o Q3CString::leftJustify() \o QString::leftJustified()
1123 \row \o Q3CString::length() \o QByteArray::length() or QByteArray::size() (equivalent)
1124 \row \o Q3CString::lower() \o QByteArray::toLower()
1125 \row \o Q3CString::rightJustify() \o QString::rightJustified()
1126 \row \o Q3CString::setExpand() \o See remark below
1127 \row \o Q3CString::simplifyWhiteSpace() \o QByteArray::simplified()
1128 \row \o Q3CString::sprintf() \o QString::sprintf()
1129 \row \o Q3CString::stripWhiteSpace() \o QByteArray::trimmed()
1130 \row \o Q3CString::toDouble() \o QString::toDouble()
1131 \row \o Q3CString::toFloat() \o QString::toFloat()
1132 \row \o Q3CString::toInt() \o QString::toInt()
1133 \row \o Q3CString::toLong() \o QString::toLong()
1134 \row \o Q3CString::toShort() \o QString::toShort()
1135 \row \o Q3CString::toUInt() \o QString::toUInt()
1136 \row \o Q3CString::toULong() \o QString::toULong()
1137 \row \o Q3CString::toUShort() \o QString::toUShort()
1138 \row \o Q3CString::upper() \o QByteArray::toUpper()
1139 \endtable
1140
1141 Remarks:
1142
1143 \list 1
1144 \o Q3CString(const char *str, uint max) constructs a string of
1145 length strlen(str) or \e max - 1, whichever is shorter.
1146 QByteArray(const char *data, int size) constructs a byte
1147 array containing exactly \e size bytes.
1148
1149 \oldcode
1150 QCString str1("Hello", 4); // "Hel"
1151 QCString str2("Hello world!", n);
1152 \newcode
1153 QByteArray str1("Hello", 3);
1154 QByteArray str2("Hello world!");
1155 str2.truncate(n - 1);
1156 \endcode
1157
1158 \o Q3CString::setExpand(uint index, char ch) has no equivalent in
1159 Qt 4.
1160
1161 \oldcode
1162 QCString str("Hello world");
1163 str.setExpand(16, '\n'); // "Hello world \n"
1164 \newcode
1165 QByteArray str("Hello world");
1166 while (str.size() < 16)
1167 str += ' ';
1168 str += '\n';
1169 \endcode
1170 \endlist
1171
1172 Since the old \c QCString class inherited from QByteArray,
1173 everything that is said in the \l{#qbytearray.section}{QByteArray
1174 section} applies for \c QCString as well.
1175
1176 \section1 QCustomEvent
1177
1178 In Qt 3, developers could create a custom event by constructing
1179 a new QCustomEvent, and send relevant data to other components in
1180 the application by passing a void pointer, either on construction or
1181 using the setData() function. Objects could receive custom events
1182 by reimplementing the \l{QObject::customEvent()}{customEvent()}
1183 function, and access the stored data using the event's data()
1184 function.
1185
1186 In Qt 4, custom events are created by subclassing
1187 QEvent. Event-specific data can be stored in a way that is
1188 appropriate for your application. Custom events are still
1189 delivered to each object's
1190 \l{QObject::customEvent()}{customEvent()} handler function, but as
1191 QEvent objects rather than as deprecated QCustomEvent objects.
1192
1193 \section1 QDataBrowser
1194
1195 The \c QDataBrowser class has been renamed Q3DataBrowser and
1196 moved to the Qt3Support library. In Qt 4.2, you should use the
1197 QDataWidgetMapper class to create data-aware forms.
1198
1199 See \l{QtSql Module} for an overview of the new SQL
1200 classes.
1201
1202 \section1 QDataPump
1203
1204 The \c QDataPump class was used internally in Qt 2.x in
1205 conjunction with QImageConsumer. It was obsoleted in Qt 3.0.
1206
1207 \input porting4-obsoletedmechanism.qdocinc
1208
1209 \section1 QDataSink
1210
1211 The \c QDataSink class was used internally in Qt 2.x in conjunction
1212 with QImageConsumer. It was obsoleted in Qt 3.0.
1213
1214 \input porting4-obsoletedmechanism.qdocinc
1215
1216 \section1 QDataSource
1217
1218 The \c QDataSource class was used internally in Qt 2.x in
1219 conjunction with QImageConsumer. It was obsoleted in Qt 3.0.
1220 \input porting4-obsoletedmechanism.qdocinc
1221
1222 \section1 QDataTable
1223
1224 The \c QDataTable class has been renamed Q3DataTable and moved to
1225 the Qt3Support library. In Qt 4.2, you should use the
1226 QDataWidgetMapper class to create data-aware forms.
1227
1228 See \l{QtSql Module} for an overview of the new SQL classes.
1229
1230 \section1 QDataView
1231
1232 The \c QDataView class has been renamed Q3DataView and moved to
1233 the Qt3Support library. In Qt 4.2, you should use the
1234 QDataWidgetMapper class to create data-aware forms.
1235
1236 See \l{QtSql Module} for an overview of the new SQL classes.
1237
1238 \section1 QDateEdit
1239
1240 The QDateEdit class in Qt 4 is a convenience class based on
1241 QDateTimeEdit. The old class has been renamed Q3DateEdit and moved
1242 to the Qt3Support library.
1243
1244 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions} for
1245 a list of \c QDateEdit virtual member functions in Qt 3 that are
1246 no longer virtual in Qt 4.
1247
1248 \section1 QDateTimeEditBase
1249
1250 The \c QDateTimeEditBase class has been renamed
1251 Q3DateTimeEditBase and moved to Qt3Support. Use QDateTimeEdit or
1252 QAbstractSpinBox instead.
1253
1254 \section1 QDateTimeEdit
1255
1256 The old \c QDateTimeEdit class has been renamed
1257 Q3DateTimeEditBase and moved to Qt3Support. The new QDateTimeEdit
1258 in Qt 4 has been rewritten from scratch to provide a more
1259 flexible and powerful API.
1260
1261 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions} for
1262 a list of QDateTimeEdit virtual member functions in Qt 3 that are no
1263 longer virtual in Qt 4.
1264
1265 \section1 QDeepCopy<T>
1266
1267 The \c QDeepCopy<T> class in Qt 3 provided a means of ensuring that
1268 implicitly shared and explicitly shared classes referenced unique
1269 data. This was necessary because the reference counting in Qt's
1270 container classes was done in a thread-unsafe manner.
1271
1272 With Qt 4, \c QDeepCopy<T> has been renamed Q3DeepCopy<T> and
1273 moved to the Qt3Support library. Removing it from
1274 existing code is straightforward.
1275
1276 \oldcode
1277 QString str1 = "I am a string";
1278 QDeepCopy<QString> str2 = str1;
1279 QString str3 = QDeepCopy<QString>(str2);
1280 \newcode
1281 QString str1 = "I am a string";
1282 QString str2 = str1;
1283 QString str3 = str2;
1284 \endcode
1285
1286 \section1 QDial
1287
1288 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions} for
1289 a list of QDial virtual member functions in Qt 3 that are no longer
1290 virtual in Qt 4.
1291
1292 See \l{#properties}{Properties} for a list of QDial properties in
1293 Qt 3 that have changed in Qt 4.
1294
1295 \target qdict.section
1296 \section1 QDict<T>
1297
1298 \c QDict<T> has been renamed Q3Dict<T> and moved to Qt3Support.
1299 It has been replaced by the more modern QHash<Key, T> and
1300 QMultiHash<Key, T> classes.
1301
1302 When porting old code that uses QDict<T> to Qt 4, there are four
1303 classes that you can use:
1304
1305 \table
1306 \header \o Qt 4 class \o When to use it
1307 \row \o QMultiHash<QString, T *>
1308
1309 \o Since Q3Dict<T> is pointer-based and allows duplicate
1310 keys, this is usually the most straightforward conversion.
1311
1312 \row \o QMultiHash<QString, T>
1313
1314 \o If type \c T is an \l{assignable data type}, you can use
1315 \c T as the value type rather than \c{T *}. This often
1316 leads to nicer code.
1317
1318 \row \o QHash<QString, T *>
1319
1320 \o{1,2} If you don't use duplicate keys, you can use QHash
1321 instead of QMultiHash. QMultiHash inherits from QHash.
1322
1323 \row \o QHash<QString, T>
1324 \endtable
1325
1326 The APIs of Q3Dict<T> and QMultiHash<QString, T *> are quite
1327 similar. The main issue is that Q3Dict supports auto-delete
1328 whereas QMultiHash doesn't.
1329
1330 \omit
1331 (See \l{What's Wrong with
1332 Auto-Delete} for an explanation of why the Qt 4 containers don't
1333 offer that feature.)
1334 \endomit
1335
1336 The following table summarizes the API differences between the
1337 two classes:
1338
1339 \table
1340 \header \o Q3Dict function \o QMultiHash equivalent
1341 \row \o Q3Dict::Q3Dict(int size, bool caseSensitive) \o See remarks below
1342 \row \o Q3Dict::autoDelete() \o N/A
1343 \row \o Q3Dict::count() \o QMultiHash::count() or QMultiHash::size() (equivalent)
1344 \row \o Q3Dict::find(const QString &) \o QMultiHash::value(const QString &)
1345 \row \o Q3Dict::remove(const QString &) \o QMultiHash::take(const QString &)
1346 \row \o Q3Dict::resize(uint) \o QMultiHash::reserve(int)
1347 \row \o Q3Dict::setAutoDelete() \o See discussion below
1348 \row \o Q3Dict::size() \o QMultiHash::capacity()
1349 \row \o Q3Dict::statistics() \o N/A
1350 \row \o Q3Dict::operator[](const QString &) \o See remark below
1351 \endtable
1352
1353 Remarks:
1354
1355 \list 1
1356 \o Q3Dict requires the user to allocate a specific number of
1357 buckets by passing a prime number (17 by default) to the
1358 constructor and/or calling Q3Dict::resize() later on. In
1359 contrast, QMultiHash's hash table automatically grows and
1360 shrinks as needed, and the constructor doesn't take a prime
1361 number.
1362
1363 \o Q3Dict supportes case-insensitive lookups by passing false as
1364 second argument to the constructor. This feature has no
1365 equivalent in QMultiHash. Instead, call QString::toLower()
1366 before you insert or lookup a key in the hash.
1367
1368 \o Q3Dict::size() and QMultiHash::size() have different semantics.
1369 The former returns the number of buckets in the container, whereas
1370 the latter returns the number of \e items in the container.
1371
1372 \o If there are multiple items with the same key,
1373 Q3Dict::remove() removes only the most recently inserted item,
1374 whereas QMultiHash::remove() removes all items that share a
1375 particular key. To remove only the most recently inserted item,
1376 call QMultiHash::take().
1377
1378 \o Q3Dict has only one [] operator (Q3Dict::operator[]()),
1379 providing const access to an item's value. QMultiHash also
1380 has a non-const overload that can be used on the left side of
1381 the assignment operator. If you use the [] operator on a
1382 non-const QHash with an unexisting item, QHash will created
1383 an element and initialize it to be a null pointer. For that
1384 reason, Q3Dict::operator[] should be converted to
1385 QMultiHash::value(), not QMultiHash::operator[].
1386
1387 \endlist
1388
1389 If you use Q3Dict's auto-delete feature (by calling
1390 Q3Dict::setAutoDelete(true)), you need to do some more work. You
1391 have two options: Either you call \c delete yourself whenever you
1392 remove an item from the container, or you use
1393 QMultiHash<QString, T> instead of QMultiHash<QString, T *> (i.e.
1394 store values directly instead of pointers to values). Here, we'll
1395 see when to call \c delete.
1396
1397 The following table summarizes the idioms that you need to watch
1398 out for if you want to call \c delete yourself.
1399
1400 \table
1401 \header \o Q3Dict idiom \o QMultiHash idiom
1402 \row
1403 \o
1404 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 9
1405 \o
1406 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 10
1407 \row
1408 \o
1409 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 11
1410 \o
1411 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 12
1412 \row
1413 \o
1414 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 13
1415
1416 (also called from Q3Dict's destructor)
1417
1418 \o
1419 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 14
1420
1421 In 99% of cases, the following idiom also works:
1422
1423 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 15
1424
1425 However, it may lead to crashes if \c hash is referenced from
1426 the value type's destructor, because \c hash contains
1427 dangling pointers until clear() is called.
1428 \endtable
1429
1430 Be aware that Q3Dict's destructor automatically calls clear(). If
1431 you have a Q3Dict data member in a custom class and use the
1432 auto-delete feature, you will need to call \c delete on all the
1433 items in the container from your class destructor to avoid a
1434 memory leak.
1435
1436 Finally, \c QDictIterator<T> (renamed Q3DictIterator<T>) must
1437 also be ported. There are no fewer than four iterator classes
1438 that can be used as a replacement: QHash::const_iterator,
1439 QHash::iterator, QHashIterator, and QMutableHashIterator. The
1440 most straightforward class to use when porting is
1441 QHashIterator<QString, T *>. The following table summarizes the
1442 API differences:
1443
1444 \table
1445 \header \o Q3DictIterator functions \o Qt 4 equivalent
1446 \row \o Q3DictIterator::count() \o QHash::count() or QHash::size()
1447 \row \o Q3DictIterator::current() \o QHashIterator::value()
1448 \row \o Q3DictIterator::currentKey() \o QHashIterator::key()
1449 \row \o Q3DictIterator::isEmpty() \o QHash::isEmpty()
1450 \row \o Q3DictIterator::toFirst() \o QHashIterator::toFront()
1451 \row \o Q3DictIterator::operator()() \o QHashIterator::value()
1452 \row \o Q3DictIterator::operator*() \o QHashIterator::value()
1453 \row \o Q3DictIterator::operator++() \o See remark below
1454 \endtable
1455
1456 Be aware that QHashIterator has a different way of iterating than
1457 Q3DictIterator. A typical loop with Q3DictIterator looks like this:
1458
1459 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 16
1460
1461 Here's the equivalent QHashIterator loop:
1462
1463 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 17
1464
1465 See \l{Java-style iterators} for details.
1466
1467 \section1 QDir
1468
1469 The following functions used to have a boolean \c{acceptAbsPath}
1470 parameter that defaulted to true:
1471
1472 \list
1473 \i QDir::filePath()
1474 \i QDir::absFilePath()
1475 \i QDir::cd()
1476 \i QDir::mkdir()
1477 \i QDir::rmdir()
1478 \i QDir::remove()
1479 \i QDir::rename()
1480 \i QDir::exists()
1481 \endlist
1482
1483 In Qt 3, if \c acceptAbsPath is true, a file name starting with
1484 '/' is be returned without change; if \c acceptAbsPath is false,
1485 an absolute path is prepended to the file name. For example:
1486
1487 \table
1488 \header \i Current directory \i File name \i \c acceptAbsPath \i File path
1489 \row \i{1,2} /home/tsmith \i{1,2} index.html \i true \i /home/tsmith/index.html
1490 \row \i false \i /home/tsmith/index.html
1491 \row \i{1,2} /home/tsmith \i{1,2} /index.html \i true \i /index.html
1492 \row \i false \i /home/tsmith/index.html
1493 \endtable
1494
1495 In Qt 4, this parameter is no longer available. If you use it
1496 in your code, you can check that QDir::isRelativePath() returns
1497 false instead.
1498
1499 \oldcode
1500 QDir dir("/home/tsmith");
1501 QString path = dir.filePath(fileName, false);
1502 \newcode
1503 QDir dir("/home/tsmith");
1504 QString path;
1505 if (dir.isRelativePath(fileName))
1506 path = dir.filePath(fileName);
1507 else
1508 path = fileName;
1509 \endcode
1510
1511 QDir::encodedEntryList() has been removed.
1512
1513 fileInfoList(), entryInfoList(), and drives() now return a QList<QFileInfo>
1514 and not a QPtrList<QFileInfo> *. Code using these methods will not work with
1515 the Qt3Support library and must be adapted instead.
1516
1517 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions} for
1518 a list of QDir virtual member functions in Qt 3 that are no longer
1519 virtual in Qt 4.
1520
1521 QDir::match() now always matches case insensitively.
1522
1523 QDir::homeDirPath() has been removed. Use QDir::home() instead, and
1524 extract the path separately.
1525
1526 \section1 QDns
1527
1528 Qt 3 used its own implementation of the DNS protocol and provided
1529 a low-level \c QDns class. Qt 4's QHostInfo class uses the system's \c
1530 gethostbyname() function from a thread instead.
1531
1532 The old \c QDns class has been renamed Q3Dns and moved to the
1533 Qt3Support library. The new QHostInfo class has a
1534 radically different API: It consists mainly of two static
1535 functions, one of which is blocking (QHostInfo::fromName()), the
1536 other non-blocking (QHostInfo::lookupHost()). See the QHostInfo
1537 class documentation for details.
1538
1539 \section1 QDockArea
1540
1541 The \c QDockArea class has been renamed Q3DockArea and moved to
1542 the Qt3Support library. In Qt 4, QMainWindow handles
1543 the dock and toolbar areas itself. See the QMainWindow
1544 documentation for details.
1545
1546 \section1 QDockWindow
1547
1548 The old \c QDockWindow class has been renamed Q3DockWindow and
1549 moved to the Qt3Support library. In Qt 4, there is a
1550 new QDockWidget class with a different API. See the class
1551 documentation for details.
1552
1553 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions} for
1554 a list of QDockWidget virtual member functions in Qt 3 that are no
1555 longer virtual in Qt 4.
1556
1557 \note \l{Q3DockWindow}'s
1558 \l{Q3DockWindow::setHorizontallyStretchable()}{horizontallyStretchable}
1559 property can be achieved in QDockWidget with
1560 \l{QWidget#Size Hints and Size Policies}{size policies}.
1561
1562 \section1 QDragObject
1563
1564 The \c QDragObject class has been renamed Q3DragObject and
1565 moved to the Qt3Support library. In Qt 4, it has been
1566 replaced by the QMimeData class. See the class documentation for
1567 details.
1568
1569 Note that the Q3DragObject::DragCopyOrMove drag and drop mode is
1570 interpreted differently to Qt 3's QDragObject::DragCopyOrMove mode.
1571 In Qt 3, a move operation was performed by default, and the user had
1572 to hold down the \key{Ctrl} key to perform a copy operation.
1573 In Qt 4, a copy operation is performed by default; the user has to
1574 hold down the \key{Shift} key to perform a move operation.
1575
1576 See \l{Porting to Qt 4 - Drag and Drop} for a comparison between
1577 the drag and drop APIs in Qt 3 and Qt 4.
1578
1579 \section1 QDropSite
1580
1581 The \c QDropSite class has been renamed Q3DropSite and moved to
1582 the Qt3Support library.
1583
1584 The QDropSite class has been obsolete ever since Qt 2.0. The only
1585 thing it does is call QWidget::setAcceptDrops(true).
1586
1587 \oldcode
1588 class MyWidget : public QWidget, public QDropSite
1589 {
1590 public:
1591 MyWidget(const QWidget *parent)
1592 : QWidget(parent), QDropSite(this)
1593 {
1594 }
1595 ...
1596 }
1597 \newcode
1598 class MyWidget : public QWidget
1599 {
1600 public:
1601 MyWidget(const QWidget *parent)
1602 : QWidget(parent)
1603 {
1604 setAcceptDrops(true);
1605 }
1606 ...
1607 }
1608 \endcode
1609
1610 See \l{Porting to Qt 4 - Drag and Drop} for a comparison between
1611 the drag and drop APIs in Qt 3 and Qt 4.
1612
1613 \section1 QEditorFactory
1614
1615 The \c QEditorFactory class has been renamed Q3EditorFactory and
1616 moved to the Qt3Support library.
1617
1618 See \l{QtSql Module} for an overview of the new SQL classes.
1619
1620 \section1 QEventLoop
1621
1622 In Qt 3, \c QEventLoop combined the Qt event loop and the event
1623 dispatching. In Qt 4, these tasks are now assigned to two
1624 distinct classes: QEventLoop and QAbstractEventDispatcher.
1625
1626 If you subclassed QEventLoop to integrate with another library's
1627 event loop, you must subclass QAbstractEventDispatcher instead. See
1628 the class documentation for details.
1629
1630 Developers using \c{QEventLoop::loopLevel()} in Qt 3 should use
1631 QCoreApplication::loopLevel() instead. Note that this function is
1632 marked as obsolete, but it is expected to be available for the
1633 lifetime of Qt 4.
1634 \omit ### mention virtual functions that aren't virtual anymore \endomit
1635
1636 \omit
1637 \section1 QFile
1638
1639 The QFile::readLine(QString&, Q_ULONG) method from qt3 has been removed
1640 in qt4, but this change in the QFile interface is not documented in the
1641 porting documentation as of qt-4.0.0-b1.
1642 \endomit
1643
1644 \section1 QFileDialog
1645
1646 The QFileDialog class in Qt 4 has been totally rewritten. It
1647 provides most of the functionality of the old \c QFileDialog
1648 class, but with a different API. Some functionality, such as the
1649 ability to preview files, is expected to be added in a later Qt 4
1650 release.
1651
1652 The old \c QFileDialog, \c QFileIconProvider, and \c QFilePreview
1653 classes has been renamed Q3FileDialog, Q3FileIconProvider, and
1654 Q3FilePreview and have been moved to Qt3Support. You can use them
1655 if you need some functionality not provided yet by the new
1656 QFileDialog class.
1657
1658 The following table lists which functions have been renamed or
1659 removed in Qt 4.
1660
1661 \table
1662 \header \o Old function \o Qt 4 equivalent
1663 \row \o Q3FileDialog::addFilter(const QString &) \o See remark below
1664 \row \o Q3FileDialog::addLeftWidget(QWidget *) \o N/A
1665 \row \o Q3FileDialog::addRightWidget(QWidget *) \o N/A
1666 \row \o Q3FileDialog::addToolButton(QAbstractButton *, bool separator) \o N/A
1667 \row \o Q3FileDialog::addWidgets(QLabel *, QWidget *, QPushButton *) \o N/A
1668 \row \o Q3FileDialog::dir() \o QFileDialog::directory()
1669 \row \o Q3FileDialog::dirPath() \o QFileDialog::directory().path()
1670 \row \o Q3FileDialog::iconProvider() \o N/A
1671 \row \o Q3FileDialog::isContentsPreviewEnabled() \o N/A
1672 \row \o Q3FileDialog::isInfoPreviewEnabled() \o N/A
1673 \row \o Q3FileDialog::previewMode() \o N/A
1674 \row \o Q3FileDialog::rereadDir() \o N/A
1675 \row \o Q3FileDialog::resortDir() \o N/A
1676 \row \o Q3FileDialog::selectAll(bool) \o N/A
1677 \row \o Q3FileDialog::setContentsPreview(QWidget *, Q3FilePreview *) \o N/A
1678 \row \o Q3FileDialog::setContentsPreviewEnabled(bool) \o N/A
1679 \row \o Q3FileDialog::setDir(const QString &) \o QFileDialog::setDirectory(const QString &)
1680 \row \o Q3FileDialog::setFilters(const char **) \o Q3FileDialog::setFilters(const QStringList &)
1681 \row \o Q3FileDialog::setIconProvider(Q3FileIconProvider *) \o N/A
1682 \row \o Q3FileDialog::setInfoPreview(QWidget *, Q3FilePreview *) \o N/A
1683 \row \o Q3FileDialog::setInfoPreviewEnabled(bool) \o N/A
1684 \row \o Q3FileDialog::setPreviewMode(PreviewMode) \o N/A
1685 \row \o Q3FileDialog::setSelectedFilter(const QString &) \o QFileDialog::selectFilter(const QString &)
1686 \row \o Q3FileDialog::setSelectedFilter(int) \o See remark below
1687 \row \o Q3FileDialog::setSelection(const QString &) \o QFileDialog::selectFile(const QString &)
1688 \row \o Q3FileDialog::setShowHiddenFiles(bool) \o showHidden()
1689 \row \o Q3FileDialog::setUrl(const QUrlOperator &) \o N/A
1690 \row \o Q3FileDialog::showHiddenFiles() \o N/A
1691 \row \o Q3FileDialog::url() \o QUrl::fromLocalFile(QFileDialog::directory())
1692 \header \o Old signals \o Qt 4 equivalent
1693 \row \o Q3FileDialog::fileHighlighted(const QString &) \o N/A
1694 \row \o Q3FileDialog::fileSelected(const QString &) \o QFileDialog::filesSelected(const QStringList &)
1695 \row \o Q3FileDialog::dirEntered(const QString &) \o N/A
1696 \row \o Q3FileDialog::filterSelected(const QString &) \o N/A
1697 \endtable
1698
1699 Remarks:
1700
1701 \list 1
1702 \o The Q3FileDialog::addFilter(const QString &) function has no
1703 direct equivalent in the new QFileDialog. Use
1704 QFileDialog::setFilters() instead.
1705
1706 \oldcode
1707 fileDialog->addFilter(tr("JPEG files (*.jpg *.jpeg)"));
1708 \newcode
1709 QStringList filters = fileDialog->filters();
1710 filters << tr("JPEG files (*.jpg *.jpeg)");
1711 fileDialog->setFilters(filters);
1712 \endcode
1713
1714 \o The Q3FileDialog::setSelectedFilter(int) overload has no direct
1715 equivalent in the new QFileDialog. Use
1716 QFileDialog::selectFilter(const QString &) instead.
1717
1718 \oldcode
1719 fileDialog->setSelectedFilter(3);
1720 \newcode
1721 fileDialog->selectFilter(fileDialog->filters().at(3));
1722 \endcode
1723 \endlist
1724
1725 There are no equivalent virtual functions to the two
1726 Q3FileDialog::setSelectedFilter() virtual functions in the QFileDialog
1727 API. In addition, these functions have been renamed or removed, as
1728 described above.
1729
1730 \section1 QFocusData
1731
1732 The QFocusData class is not available in Qt 4. Some of its
1733 functionality is available via the QWidget::nextInFocusChain()
1734 and QWidget::focusNextPrevChild() functions.
1735
1736 \section1 QFocusEvent
1737
1738 The setReason() function is no longer present in Qt 4. It is
1739 necessary to define the reason when constructing a focus event.
1740
1741 \section1 QFont
1742
1743 \c QFont::Script has been moved to QFontDatabase::WritingSystem.
1744
1745 \section1 QFrame
1746
1747 The QFrame class has been made more lightweight in Qt 4, by
1748 reducing the number of properties and virtual functions. The
1749 reduction in the number of virtual functions is significant
1750 because QFrame is the base class of many Qt classes.
1751
1752 Here's an overview of the changes:
1753
1754 \list
1755 \o QFrame no longer has a \c margin property (which wasn't
1756 honored by Qt's layout managers anyway).
1757
1758 \o QFrame no longer has a frameChanged() function, reimplement
1759 QFrame::resizeEvent() instead.
1760
1761 \o QFrame used to have drawFrame(QPainter *) and
1762 drawContents(QPainter *) virtual functions. These are now
1763 gone. In Qt 4, the frame is drawn by the QFrame::paintEvent()
1764 function. If you want to change the way QFrame paints itself,
1765 reimplement this function. To draw the contents of the frame,
1766 reimplement QFrame:paintEvent() and call the base class
1767 implementation of the function before you use the
1768 \l {QWidget::}{contentsRect()} function inherited from QWidget,
1769 to retrieve the rectangle to paint on.
1770
1771 \endlist
1772
1773 To help with porting, the Qt3Support library contains a Q3Frame
1774 class that inherits QFrame and provides a similar API to the old
1775 QFrame class. If you derived from QFrame in your application, you
1776 might want to use Q3Frame as a base class as a first step in the
1777 porting process, and later move on to the new QFrame class.
1778
1779 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions} for
1780 a list of QFrame virtual member functions in Qt 3 that are no longer
1781 virtual in Qt 4.
1782
1783 \section1 QFtp
1784
1785 QFtp no longer inherits from QNetworkProtocol. See the
1786 \l{#qnetworkprotocol.section}{section on QNetworkProtocol} for
1787 details.
1788
1789 The old \c QFtp class has been renamed Q3Ftp and moved to the
1790 Qt3Support library.
1791
1792 \target qglayoutiterator.section
1793 \section1 QGLayoutIterator
1794
1795 The QGLayoutIterator class no longer exists in Qt 4. This makes
1796 only a difference if you implemented custom layout managers
1797 (i.e., QLayout subclasses).
1798
1799 The new approach is much simpler: It consists in reimplementing
1800 QLayout::itemAt() and QLayout::takeAt(). These functions operate
1801 on indexes, eliminating the need for a layout iterator class.
1802
1803 \section1 QGrid
1804
1805 The \c QGrid class is now only available as Q3Grid in Qt 4. You
1806 can achieve the same result as \c QGrid by creating a QWidget
1807 with a grid layout:
1808
1809 \oldcode
1810 QGrid *grid = new QGrid(2, Qt::Horizontal);
1811 QPushButton *child1 = new QPushButton(grid);
1812 QPushButton *child2 = new QPushButton(grid);
1813 QPushButton *child3 = new QPushButton(grid);
1814 QPushButton *child4 = new QPushButton(grid);
1815 \newcode
1816 QWidget *grid = new QWidget;
1817 QPushButton *child1 = new QPushButton(grid);
1818 QPushButton *child2 = new QPushButton(grid);
1819 QPushButton *child3 = new QPushButton(grid);
1820 QPushButton *child4 = new QPushButton(grid);
1821
1822 QVBoxLayout *layout = new QVBoxLayout;
1823 layout->addWidget(child1, 0, 0);
1824 layout->addWidget(child2, 0, 1);
1825 layout->addWidget(child3, 1, 0);
1826 layout->addWidget(child4, 1, 1);
1827 grid->setLayout(layout);
1828 \endcode
1829
1830 \section1 QGridLayout
1831
1832 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions} for
1833 a list of QGridLayout virtual member functions in Qt 3 that are no
1834 longer virtual in Qt 4.
1835
1836 \section1 QGridView
1837
1838 The \c QGridView class has been renamed Q3GridView and moved to
1839 the Qt3Support library. In Qt 4, we recommend that
1840 you use QTableView or QAbstractItemView for presenting tabular
1841 data.
1842
1843 See \l{Model/View Programming} for an overview of the new item
1844 view classes.
1845
1846 \target qgroupbox.section
1847 \section1 QGroupBox
1848
1849 The QGroupBox class has been redesigned in Qt 4. Many of the
1850 features of the old \c QGroupBox class can be obtained by using
1851 the Q3GroupBox class from the Qt3Support library.
1852
1853 The new QGroupBox is more lightweight. It doesn't attempt to
1854 duplicate functionality already provided by QGridLayout, and it
1855 does not inherit from QFrame. As a result, the following members
1856 have been removed:
1857
1858 \list
1859 \o Q3GroupBox::setColumns(), Q3GroupBox::columns()
1860 \o Q3GroupBox::setOrientation(), Q3GroupBox::orientation()
1861 \o Q3GroupBox::setInsideMargin(), Q3GroupBox::insideMargin()
1862 \o Q3GroupBox::addSpace()
1863 \endlist
1864
1865 Naturally, the \c columns and \c orientation properties have also
1866 been removed.
1867
1868 If you rely on some of the missing functionality in your
1869 application, you can use Q3GroupBox instead of QGroupBox as a
1870 help to porting.
1871
1872 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions} for
1873 a list of QGroupBox virtual member functions in Qt 3 that are no
1874 longer virtual in Qt 4.
1875
1876 \section1 QHBox
1877
1878 The \c QHBox class is now only available as Q3HBox in Qt 4. You
1879 can achieve the same result as \c QHBox by creating a QWidget
1880 with an horizontal layout:
1881
1882 \oldcode
1883 QHBox *hbox = new QHBox;
1884 QPushButton *child1 = new QPushButton(hbox);
1885 QPushButton *child2 = new QPushButton(hbox);
1886 \newcode
1887 QWidget *hbox = new QWidget;
1888 QPushButton *child1 = new QPushButton;
1889 QPushButton *child2 = new QPushButton;
1890
1891 QHBoxLayout *layout = new QHBoxLayout;
1892 layout->addWidget(child1);
1893 layout->addWidget(child2);
1894 hbox->setLayout(layout);
1895 \endcode
1896
1897 Note that child widgets are not automatically placed into the widget's
1898 layout; you will need to manually add each widget to the QHBoxLayout.
1899
1900 \section1 QHeader
1901
1902 The \c QHeader class has been renamed Q3Header and moved to
1903 the Qt3Support library. In Qt 4, it is replaced
1904 by the QHeaderView class.
1905
1906 See \l{Model/View Programming} for an overview of the new item
1907 view classes.
1908
1909 \section1 QHGroupBox
1910
1911 The \c QHGroupBox class has been renamed Q3HGroupBox and moved to
1912 the Qt3Support library.
1913 Qt 4 does not provide a specific replacement class for \c QHGroupBox
1914 since QGroupBox is designed to be a generic container widget. As a
1915 result, you need to supply your own layout for any child widgets.
1916
1917 See \l{#QGroupBox} for more information about porting code that uses
1918 group boxes.
1919
1920 \section1 QHttp
1921
1922 QHttp no longer inherits from QNetworkProtocol. See the See the
1923 \l{#qnetworkprotocol.section}{section on QNetworkProtocol} for
1924 details.
1925
1926 The old \c QHttp, \c QHttpHeader, \c QHttpRequestHeader, and \c
1927 QHttpResponseHeader classes have been renamed Q3Http,
1928 Q3HttpHeader, Q3HttpRequestHeader, and Q3HttpResponseHeader and
1929 have been moved to the Qt3Support library.
1930
1931 \section1 QIconFactory
1932
1933 The QIconFactory class is no longer part of Qt. It has been replaced by
1934 the QIconEngine class.
1935
1936 \section1 QIconSet
1937
1938 The QIconSet class is no longer part of Qt. It has been replaced by
1939 the QIcon class.
1940
1941 \section1 QIconView
1942
1943 The \c QIconView, \c QIconViewItem, \c QIconDrag, and \c
1944 QIconDragItem classes has been renamed Q3IconView,
1945 Q3IconViewItem, Q3IconDrag, and Q3IconDragItem and moved to the
1946 Qt3Support library. New Qt applications should use
1947 QListWidget or its base class QListView instead, and call
1948 QListView::setViewMode(QListView::IconMode) to obtain an "icon
1949 view" look.
1950
1951 See \l{Model/View Programming} for an overview of the new item
1952 view classes.
1953
1954 \omit
1955 ###
1956
1957 \section1 QImage
1958
1959 QImage::fromMimeSource(const QString &) -> qImageFromMimeSource(const QString &)
1960 \endomit
1961
1962 \section1 QImageDrag
1963
1964 The \c QImageDrag class has been renamed Q3ImageDrag and moved to
1965 the Qt3Support library. In Qt 4, use QMimeData
1966 instead and call QMimeData::setImage() to set the image.
1967
1968 See \l{Porting to Qt 4 - Drag and Drop} for a comparison between
1969 the drag and drop APIs in Qt 3 and Qt 4.
1970
1971 \section1 QImageIO
1972
1973 The \c QImageIO class has been split into two classes:
1974 QImageReader and QImageWriter. The table below shows the
1975 correspondance between the two APIs:
1976
1977 \table
1978 \header \o Qt 3 function \o Qt 4 equivalents
1979 \row \o QImageIO::description() \o QImageWriter::description()
1980 \row \o QImageIO::fileName() \o QImageReader::fileName() and QImageWriter::fileName()
1981 \row \o QImageIO::format() \o QImageReader::format() and QImageWriter::format()
1982 \row \o QImageIO::gamma() \o QImageWriter::gamma()
1983 \row \o QImageIO::image() \o Return value of QImageReader::read()
1984 \row \o QImageIO::inputFormats() \o QImageReader::supportedImageFormats()
1985 \row \o QImageIO::ioDevice() \o QImageReader::device() and QImageWriter::device()
1986 \row \o QImageIO::outputFormats() \o QImageWriter::supportedImageFormats()
1987 \row \o QImageIO::parameters() \o N/A
1988 \row \o QImageIO::quality() \o QImageWriter::quality()
1989 \row \o QImageIO::read() \o QImageReader::read()
1990 \row \o QImageIO::setDescription() \o QImageWriter::setDescription()
1991 \row \o QImageIO::setFileName() \o QImageReader::setFileName() and QImageWriter::setFileName()
1992 \row \o QImageIO::setFormat() \o QImageReader::setFormat() and QImageWriter::setFormat()
1993 \row \o QImageIO::setGamma() \o QImageWriter::setGamma()
1994 \row \o QImageIO::setIODevice() \o QImageReader::setDevice() and QImageWriter::setDevice()
1995 \row \o QImageIO::setImage() \o Argument to QImageWriter::write()
1996 \row \o QImageIO::setParameters() \o N/A
1997 \row \o QImageIO::setQuality() \o QImageWriter::setQuality()
1998 \row \o QImageIO::setStatus() \o N/A
1999 \row \o QImageIO::status() \o QImageReader::error() and QImageWriter::error()
2000 \row \o QImageIO::write() \o QImageWriter::write()
2001 \endtable
2002
2003 \section1 QIntCache<T>
2004
2005 QIntCache<T> has been moved to Qt3Support. It has been replaced
2006 by QCache<int, T>.
2007
2008 For details, read the \l{#qcache.section}{section on QCache<T>},
2009 mentally substituting \c int for QString.
2010
2011 \section1 QIntDict<T>
2012
2013 QIntDict<T> and QIntDictIterator<T> have been moved to
2014 Qt3Support. They have been replaced by the more modern QHash<Key,
2015 T> and QMultiHash<Key, T> classes and their associated iterator
2016 classes.
2017
2018 When porting old code that uses QIntDict<T> to Qt 4, there are
2019 four classes that you can use:
2020
2021 \list
2022 \o QMultiHash<int, T *>
2023 \o QMultiHash<int, T>
2024 \o QHash<int, T *>
2025 \o QHash<int, T>
2026 \endlist
2027
2028 For details, read the \l{#qdict.section}{section on QDict<T>},
2029 mentally substituting \c int for QString.
2030
2031 \target qiodevice.section
2032 \section1 QIODevice
2033
2034 The QIODevice class's API has been simplified to make it easier
2035 to subclass and to make it work more smoothly with asynchronous
2036 devices such as QTcpSocket and QProcess.
2037
2038 The following virtual functions have changed name or signature:
2039
2040 \table
2041 \header \o Qt 3 function \o Comment
2042 \row \o QIODevice::at() const \o Renamed QIODevice::pos().
2043 \row \o QIODevice::at(Offset) \o Renamed QIODevice::seek().
2044 \row \o QIODevice::open(int) \o The parameter is now of type QIODevice::OpenMode.
2045 \row \o QIODevice::readBlock(char *, Q_ULONG) \o QIODevice::read(char *, qint64)
2046 \row \o QIODevice::writeBlock(const char *, Q_ULONG) \o QIODevice::write(const char *, qint64)
2047 \endtable
2048
2049 \note QIODevice::open(QIODevice::OpenMode) is no longer pure virtual.
2050
2051 The following functions are no longer virtual or don't exist anymore:
2052
2053 \table
2054 \row \o QIODevice::getch() \o Renamed QIODevice::getChar() and implemented in terms of QIODevice::readData().
2055 \row \o QIODevice::putch(int) \o Renamed QIODevice::putChar() and implemented in terms of QIODevice::writeData().
2056 \row \o QIODevice::readAll() \o Implemented in terms of QIODevice::readData().
2057 \row \o QIODevice::readLine(char *, Q_ULONG) \o Implemented in terms of QIODevice::readData()
2058 \row \o QIODevice::ungetch(int) \o Renamed QIODevice::ungetChar() and simulated using an internal unget buffer.
2059 \endtable
2060
2061 The \c IO_xxx flags have been revised, and the protected setFlags()
2062 function removed. Most of the flags have been
2063 eliminated because errors are best handled by implementing certain
2064 functions in QIODevice subclasses rather than through the base classes.
2065 The file access flags, such as \c IO_ReadOnly and \c IO_WriteOnly, have
2066 been moved to the QIODevice class to avoid polluting the global
2067 namespace. The table below shows the correspondence between the
2068 Qt 3 \c IO_xxx flags and the Qt 4 API:
2069
2070 \table
2071 \header \o Qt 3 constant \o Qt 4 equivalent
2072 \row \o IO_Direct \o Use !QIODevice::isSequential() instead (notice the \e not).
2073 \row \o IO_Sequential \o Use QIODevice::isSequential() instead.
2074 \row \o IO_Combined \o N/A
2075 \row \o IO_TypeMask \o N/A
2076 \row \o IO_Raw \o QIODevice::Unbuffered
2077 \row \o IO_Async \o N/A
2078 \row \o IO_ReadOnly \o QIODevice::ReadOnly
2079 \row \o IO_WriteOnly \o QIODevice::WriteOnly
2080 \row \o IO_ReadWrite \o QIODevice::ReadWrite
2081 \row \o IO_Append \o QIODevice::Append
2082 \row \o IO_Truncate \o QIODevice::Truncate
2083 \row \o IO_Translate \o QIODevice::Text
2084 \row \o IO_ModeMask \o N/A
2085 \row \o IO_Open \o Use QIODevice::isOpen() instead.
2086 \row \o IO_StateMask \o N/A
2087 \row \o IO_Ok \o N/A
2088 \row \o IO_ReadError \o N/A
2089 \row \o IO_WriteError \o N/A
2090 \row \o IO_FatalError \o N/A
2091 \row \o IO_ResourceError \o N/A
2092 \row \o IO_OpenError \o N/A
2093 \row \o IO_ConnectError \o N/A
2094 \row \o IO_AbortError \o N/A
2095 \row \o IO_TimeOutError \o N/A
2096 \row \o IO_UnspecifiedError \o N/A
2097 \endtable
2098
2099 \section1 QIODeviceSource
2100
2101 The QIODeviceSource class was used internally in Qt 2.x in
2102 conjunction with QImageConsumer. It was obsoleted in Qt 3.0.
2103 \input porting4-obsoletedmechanism.qdocinc
2104
2105 \section1 QLabel
2106
2107 QLabel doesn't enable word-wrap automatically anymore when rich
2108 text is used. You can enable it by calling
2109 QLabel::setWordWrap() or by setting the
2110 \l{QLabel::wordWrap}{wordWrap} property. The reason for this
2111 change is that the old behavior was confusing to many users.
2112
2113 Also, QLabel no longer offers an \c autoResize property. Instead,
2114 you can call QWidget::setFixedSize() on the label, with
2115 QLabel::sizeHint() as the argument, whenever you change the
2116 contents of the QLabel.
2117
2118 See also \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions}
2119 for a list of QLabel virtual member functions in Qt 3 that are no
2120 longer virtual in Qt 4.
2121
2122 \section1 QLayout
2123
2124 In Qt 4, margins are always handled by layouts; there is no
2125 QLayout::setSupportsMargin() function anymore.
2126
2127 The deleteAllItems() function is now only available if
2128 \c QT3_SUPPORT is defined. If you maintain a QList of layout
2129 items, you can use qDeleteAll() to remove all the items in one
2130 go.
2131
2132 In Qt 3, it was possible to change the resizing behavior for layouts
2133 in top-level widgets by adjusting the layout's \c resizeMode property.
2134 In Qt 4, this property has been replaced by the QLayout::sizeConstraint
2135 property which provides more control over how the layout behaves when
2136 resized.
2137
2138 See also the \l{#qlayoutiterator.section}{section on
2139 QLayoutIterator} and the \l{#qglayoutiterator.section}{section on
2140 QGLayoutIterator}.
2141
2142 \target qlayoutiterator.section
2143 \section1 QLayoutIterator
2144
2145 The QLayoutIterator class is obsoleted in Qt 4. It is available
2146 only if \c QT3_SUPPORT is defined. It can be replaced by the
2147 QLayout::itemAt() and QLayout::takeAt() functions, which operate
2148 on indexes.
2149
2150 \oldcode
2151 QLayoutIterator it = layout()->iterator();
2152 QLayoutItem *child;
2153 while ((child = it.current()) != 0) {
2154 if (child->widget() == myWidget) {
2155 it.takeCurrent();
2156 return;
2157 ++it;
2158 }
2159 \newcode
2160 int i = 0;
2161 QLayoutItem *child;
2162 while ((child = layout()->itemAt(i)) != 0) {
2163 if (child->widget() == myWidget) {
2164 layout()->takeAt(i);
2165 return;
2166 }
2167 ++i;
2168 }
2169 \endcode
2170
2171 \section1 QLineEdit
2172
2173 See \l{#properties}{Properties} for a list of QLineEdit
2174 properties in Qt 3 that have changed in Qt 4.
2175
2176 The default value of QLineEdit's \l{QLineEdit::dragEnabled()}{dragEnabled}
2177 property was \c true in Qt 3. In Qt 4, the default value is \c false.
2178
2179 Note that QLineEdit in Qt 4 is no longer a subclass of QFrame.
2180 If you need to visually style a line edit with a frame, we recommend
2181 either using a QFrame as a container for a QLineEdit or customizing
2182 the line edit with a \l{Qt Style Sheets}{style sheet}.
2183
2184 \section1 QListBox
2185
2186 The \c QListBox, \c QListBoxItem, \c QListBoxText, and \c
2187 QListBoxPixmap classes have been renamed Q3ListBox,
2188 Q3ListBoxItem, Q3ListBoxText, and Q3ListBoxPixmap and have been
2189 moved to the Qt3Support library. New Qt applications
2190 should use QListWidget or its base class QListView instead.
2191
2192 See \l{Model/View Programming} for an overview of the new item
2193 view classes.
2194
2195 \section1 QListView
2196
2197 The \c QListView, \c QListViewItem, \c QCheckListItem, and \c
2198 QListViewItemIterator classes have been renamed Q3ListView,
2199 Q3ListViewItem, Q3CheckListItem, and Q3ListViewItemIterator, and
2200 have been moved to the Qt3Support library. New Qt
2201 applications should use one of the following four classes
2202 instead: QTreeView or QTreeWidget for tree-like structures;
2203 QListWidget or the new QListView class for one-dimensional lists.
2204
2205 See \l{Model/View Programming} for an overview of the new item
2206 view classes.
2207
2208 \section1 QLocalFs
2209
2210 The \c QLocalFs class is no longer part of the public Qt API. It
2211 has been renamed Q3LocalFs and moved to Qt3Support. Use QDir,
2212 QFileInfo, or QFile instead.
2213
2214 \section1 QMainWindow
2215
2216 The QMainWindow class has been redesigned in Qt 4 to provide a
2217 more modern look and feel and more flexibility. The API has
2218 changed to reflect that. The old \c QMainWindow class has been
2219 renamed Q3MainWindow and moved to Qt3Support. See the QMainWindow
2220 class documentation for details.
2221
2222 \omit ### More detail \endomit
2223
2224 \target qmemarray.section
2225 \section1 QMemArray<T>
2226
2227 QMemArray<T> has been moved to Qt3Support. It has been replaced
2228 by the QVector<T> class.
2229
2230 The following table summarizes the API differences between the
2231 two classes.
2232
2233 \table
2234 \row \o QMemArray::assign(const QMemArray<T> &) \o QVector::operator=()
2235 \row \o QMemArray::assign(const T *, uint) \o See remark below
2236 \row \o QMemArray::duplicate(const QMemArray &) \o QVector::operator=()
2237 \row \o QMemArray::duplicate(const T *, uint) \o See remark below
2238 \row \o QMemArray::setRawData(const T *, uint) \o N/A
2239 \row \o QMemArray::resetRawData(const T *, uint) \o N/A
2240 \row \o QMemArray::find(const T &, uint) \o QVector::indexOf(const T &, int)
2241 \row \o QMemArray::contains(const T &) \o QVector::count(const T &)
2242 \row \o QMemArray::sort() \o \l qSort()
2243 \row \o QMemArray::bsearch(const T &d) \o \l qBinaryFind()
2244 \row \o QMemArray::at(uint) \o QVector::operator[]()
2245 \row \o QMemArray::operator const T *() \o QVector::constData()
2246 \endtable
2247
2248 Remarks:
2249
2250 \list 1
2251 \o QMemArray::assign(const T *, uint) and QMemArray::duplicate(const T *, uint)
2252 can be replaced by QVector::resize() and qCopy().
2253
2254 \oldcode
2255 QMemArray<QSize> array;
2256 ...
2257 array.assign(data, size);
2258 \newcode
2259 QVector<QSize> vector;
2260 ...
2261 vector.resize(size);
2262 qCopy(data, data + size, vector.begin());
2263 \endcode
2264
2265 \o QMemArray is an explicitly shared class, whereas QVector is
2266 implicitly shared. See \l{Explicit Sharing} for more
2267 information.
2268 \endlist
2269
2270 \section1 QMenuBar
2271
2272 In Qt 3, QMenuBar inherited from QFrame and QMenuData; in Qt 4, it is
2273 a direct subclass of QWidget. Applications that provided customized
2274 menu bars will need to take advantage of the styling features described
2275 in the \l{Qt Style Sheets} document.
2276
2277 It is not possible to add widgets to menu bars in Qt 4.
2278
2279 \section1 QMenuData
2280
2281 In Qt 4, the QMenu class provides a menu widget that can be used in all
2282 the places where menus are used in an application. Unlike \c QMenuData,
2283 QMenu is designed around the concept of actions, provided by the QAction
2284 class, instead of the identifiers used in Qt 3.
2285
2286 In Qt 3, it was possible to insert widgets directly into menus by using
2287 a specific \c QMenuData::insertItem() overload. In Qt 4.2 and later,
2288 the QWidgetAction class can be used to wrap widgets for use in Qt 4's
2289 action-based APIs.
2290
2291 \section1 QMessageBox
2292
2293 The QMessageBox::iconPixmap() function used to return a "const
2294 QPixmap *". In Qt 4, it returns a QPixmap.
2295
2296 \section1 QMimeSourceFactory
2297
2298 The \c QMimeSourceFactory has been renamed Q3MimeSourceFactory
2299 and moved to the Qt3Support library. New Qt applications should
2300 use Qt 4's \l{Resource System} instead.
2301
2302 \section1 QMovie
2303
2304 The QMovie API has been revised in Qt 4 to make it more
2305 consistent with the other Qt classes (notably QImageReader). The
2306 table below summarizes the changes.
2307
2308 \table
2309 \header \o Qt 3 function \o Qt 4 equivalent
2310 \row \o QMovie::connectResize() \o Connect to QMovie::resized()
2311 \row \o QMovie::connectStatus() \o Connect to QMovie::stateChanged()
2312 \row \o QMovie::connectUpdate() \o Connect to QMovie::updated()
2313 \row \o QMovie::disconnectResize() \o Disconnect from QMovie::resized()
2314 \row \o QMovie::disconnectStatus() \o Disconnect from QMovie::stateChanged()
2315 \row \o QMovie::disconnectUpdate() \o Disconnect from QMovie::updated()
2316 \row \o QMovie::finished() \o Use QMovie::state() instead
2317 \row \o QMovie::frameImage() \o Use QMovie::currentImage() instead
2318 \row \o QMovie::frameNumber() \o Use QMovie::currentFrameNumber() instead
2319 \row \o QMovie::framePixmap() \o Use QMovie::currentPixmap() instead
2320 \row \o QMovie::getValidRect() \o Use frameRect() instead
2321 \row \o QMovie::isNull() \o Use QMovie::isValid() instead
2322 \row \o QMovie::pause() \o Use QMovie::setPaused(true) instead
2323 \row \o QMovie::paused() \o Use QMovie::state() instead
2324 \row \o QMovie::pushData() \o N/A
2325 \row \o QMovie::pushSpace() \o N/A
2326 \row \o QMovie::restart() \o Use QMovie::jumpToFrame(0) instead
2327 \row \o QMovie::running() \o Use QMovie::state() instead
2328 \row \o QMovie::step() \o Use QMovie::jumpToFrame() and QMovie::setPaused() instead
2329 \row \o QMovie::step() \o Use QMovie::jumpToNextFrame() instead
2330 \row \o QMovie::steps() \o Use QMovie::currentFrameNumber() and QMovie::frameCount() instead
2331 \row \o QMovie::unpause() \o Use QMovie::setPaused(false) instead
2332 \endtable
2333
2334 \section1 QMultiLineEdit
2335
2336 The \c QMultiLineEdit class in Qt 3 was a convenience QTextEdit
2337 subclass that provided an interface compatible with Qt 2's
2338 QMultiLineEdit class. In Qt 4, it is called Q3MultiLineEdit, it
2339 inherits Q3TextEdit, and it is part of Qt3Support. Use QTextEdit
2340 in new code.
2341
2342 \target qnetworkprotocol.section
2343 \section1 QNetworkProtocol
2344
2345 The QNetworkProtocol, QNetworkProtocolFactoryBase,
2346 QNetworkProtocolFactory<T>, and QNetworkOperation classes are no
2347 longer part of the public Qt API. They have been renamed
2348 Q3NetworkProtocol, Q3NetworkProtocolFactoryBase,
2349 Q3NetworkProtocolFactory<T>, and Q3NetworkOperation and have been
2350 moved to the Qt3Support library.
2351
2352 In Qt 4 applications, you can use classes like QFtp and QHttp
2353 directly to perform file-related actions on a remote host.
2354
2355 \section1 QObject
2356
2357 QObject::children() now returns a QObjectList instead of a
2358 pointer to a QObjectList. See also the comments on QObjectList
2359 below.
2360
2361 Use QObject::findChildren() (or qFindChildren() if you need MSVC 6
2362 compatibility) instead of QObject::queryList(). For example:
2363
2364 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 18
2365
2366 QObject::killTimers() has been removed because it was unsafe to
2367 use in subclass. (A subclass normally doesn't know whether the
2368 base class uses timers or not.)
2369
2370 The \c QObject::name property has been renamed
2371 QObject::objectName.
2372
2373 \c QObject::objectTrees() has been removed. If you are primarly
2374 interested in widgets, use QApplication::allWidgets() or
2375 QApplication::topLevelWidgets().
2376
2377 \section1 QObjectDictionary
2378
2379 The QObjectDictionary class is a synonym for
2380 QAsciiDict<QMetaObject>. See the \l{#qasciidict.section}{section
2381 on QAsciiDict<T>}.
2382
2383 \section1 QObjectList
2384
2385 In Qt 3, the QObjectList class was a typedef for
2386 QPtrList<QObject>. In Qt 4, it is a typedef for QList<QObject *>.
2387 See the \l{#qptrlist.section}{section on QPtrList<T>}.
2388
2389 \section1 QPaintDevice
2390
2391 To reimplement painter backends one previously needed to reimplement
2392 the virtual function QPaintDevice::cmd(). This function is taken out
2393 and should is replaced with the function QPaintDevice::paintEngine()
2394 and the abstract class QPaintEngine. QPaintEngine provides virtual
2395 functions for all drawing operations that can be performed on a
2396 painter backend.
2397
2398 bitBlt() and copyBlt() are now only compatibility functions. Use
2399 QPainter::drawPixmap() instead.
2400
2401 \section1 QPaintDeviceMetrics
2402
2403 All functions that used to be provided by the \c
2404 QPaintDeviceMetrics class have now been moved to QPaintDevice.
2405
2406 \oldcode
2407 QPaintDeviceMetrics metrics(widget);
2408 int deviceDepth = metrics.depth();
2409 \newcode
2410 int deviceDepth = widget->depth();
2411 \endcode
2412
2413 For compatibility, the old \c QPaintDeviceMetrics class has been
2414 renamed Q3PaintDeviceMetrics and moved to Qt3Support.
2415
2416 \section1 QPainter
2417
2418 The QPainter class has undergone some changes in Qt 4 because of
2419 the way rectangles are drawn. In Qt 4, the result of drawing a
2420 QRect with a pen width of 1 pixel is 1 pixel wider and 1 pixel
2421 taller than in Qt 3.
2422
2423 For compatibility, we provide a Q3Painter class in Qt3Support
2424 that provides the old semantics. See the Q3Painter documentation
2425 for details and for the reasons why we had to make this change.
2426
2427 The \l{http://doc.trolltech.com/3.3/qpainter.html#CoordinateMode-enum}{QPainter::CoordinateMode}
2428 enum has been removed in Qt 4. All clipping
2429 operations are now defined using logical coordinates and are subject
2430 to transformation operations.
2431
2432 The
2433 \l{http://doc.trolltech.com/3.3/qpainter.html#RasterOP-enum}{QPainter::RasterOP}
2434 enum has been replaced with QPainter::CompositionMode.
2435
2436 \section1 QPicture
2437
2438 In Qt 3, a QPicture could be saved in the SVG file format. In Qt
2439 4, the SVG support is provided by the QtSvg module, which
2440 includes classes for \e displaying the contents of SVG files.
2441
2442 If you would like to generate SVG files, you can use the Q3Picture
2443 compatibility class or the QSvgGenerator class introduced in Qt 4.3.
2444
2445 \section1 QPixmap
2446
2447 The mask() function has been changed to return a reference to a QBitmap
2448 rather than a pointer. As a result, it is no longer possible simply to
2449 test for a null pointer when determining whether a pixmap has a mask.
2450 Instead, you need to explicitly test whether the mask bitmap is null or
2451 not.
2452
2453 \oldcode
2454 if (pixmap.mask())
2455 widget->setMask(*pixmap.mask());
2456 \newcode
2457 if (!pixmap.mask().isNull())
2458 widget->setMask(pixmap.mask());
2459 \endcode
2460
2461 The \c QPixmap::setOptimization() and \c QPixmap::setDefaultOptimization()
2462 mechanism is no longer available in Qt 4.
2463
2464\omit
2465 QPixmap::fromMimeSource(const QString &) -> qPixmapFromMimeSource(const QString &)
2466\endomit
2467
2468 \section1 QPointArray
2469
2470 The \c QPointArray class has been renamed QPolygon in Qt 4 and
2471 has undergone significant changes. In Qt 3, \c QPointArray
2472 inherited from QMemArray<QPoint>. In Qt 4, QPolygon inherits from
2473 QVector<QPoint>. Everything mentioned in the
2474 \l{#qmemarray.section}{section on QMemArray<T>} apply for
2475 QPointArray as well.
2476
2477 The Qt3Support library contains a Q3PointArray class
2478 that inherits from QPolygon and provides a few functions that
2479 existed in \c QPointArray but no longer exist in QPolygon. These
2480 functions include Q3PointArray::makeArc(),
2481 Q3PointArray::makeEllipse(), and Q3PointArray::cubicBezier().
2482 In Qt 4, we recommend that you use QPainterPath for representing
2483 arcs, ellipses, and Bezier curves, rather than QPolygon.
2484
2485 The QPolygon::setPoints() and QPolygon::putPoints() functions
2486 return \c void in Qt 4. The corresponding Qt 3 functions returned
2487 a \c bool indicating whether the array was successfully resized
2488 or not. This can now be checked by checking QPolygon::size()
2489 after the call.
2490
2491\omit
2492 X11 Specific:
2493
2494 ::appDisplay() -> QX11Info::display()
2495 QPaintDevice::x11Display() -> QX11Info::display()
2496 QPaintDevice::x11AppDisplay() -> QX11Info::display()
2497 QPaintDevice::x11Screen() -> QX11Info::appScreen()
2498 QPaintDevice::x11AppScreen() -> ???
2499 QPaintDevice::x11Depth() -> QX11Info::appDepth()
2500 QPaintDevice::x11ColorMap() -> QX11Info::appColorMap()
2501 QPaintDevice::x11DefaultColorMap() -> ???
2502 QPaintDevice::x11Visual() -> QX11Info::appVisual()
2503 QPaintDevice::x11DefaultVisual() -> ???
2504
2505 QPaintDevice::x11AppDpiX() -> QX11Info::appDpiX()
2506 QPaintDevice::x11AppDpiY() -> QX11Info::appDpiY()
2507 QPaintDevice::x11SetAppDpiX() -> QX11Info::setAppDpiX()
2508 QPaintDevice::x11SetAppDpiY() -> QX11Info::setAppDpiY()
2509
2510 QPaintDevice::x11AppDepth() -> ???
2511 QPaintDevice::x11AppCells() -> ???
2512 QPaintDevice::x11AppRootWindow() -> ???
2513 QPaintDevice::x11AppColorMap() -> ???
2514 QPaintDevice::x11AppDefaultColorMap() -> ???
2515 QPaintDevice::x11AppVisual() -> ???
2516 QPaintDevice::x11AppDefaultVisual() -> ???
2517
2518 End of X11 Specific
2519\endomit
2520
2521 \section1 QPopupMenu
2522
2523 For most purposes, QPopupMenu has been replaced by QMenu in Qt
2524 4. For compatibility with older applications, Q3PopupMenu provides
2525 the old API and features that are specific to pop-up menus. Note
2526 that, when using Q3PopupMenu, the menu's actions must be \l
2527 {Q3Action}s.
2528
2529 In Qt 3, it was common practice to add entries to pop-up menus using the
2530 insertItem() function, maintaining identifiers for future use; for
2531 example, to dynamically change menu items.
2532 In Qt 4, menu entries are completely represented
2533 by actions for consistency with other user interface components, such as
2534 toolbar buttons. Create new menus with the QMenu class, and use the
2535 overloaded QMenu::addAction() functions to insert new entries.
2536 If you need to manage a set of actions created for a particular menu,
2537 we suggest that you construct a QActionGroup and add them to that.
2538
2539 The \l{Qt Examples#Main Windows}{Main Window examples} provided
2540 show how to use Qt's action system to construct menus, toolbars, and other
2541 common user interface elements.
2542
2543 \section1 QPrinter
2544
2545 The QPrinter class now expects printing to be set up from a
2546 QPrintDialog.
2547
2548 \section1 QProcess
2549
2550 The QProcess class has undergone major improvements in Qt 4. It
2551 now inherits QIODevice, which makes it possible to combine
2552 QProcess with a QTextStream or a QDataStream.
2553
2554 The old \c QProcess class has been renamed Q3Process and moved to
2555 the Qt3Support library.
2556
2557 \section1 QProgressBar
2558
2559 The QProgressBar API has been significantly improved in Qt 4. The
2560 old \c QProgressBar API is available as Q3ProgressBar in the
2561 Qt3Support library.
2562
2563 \section1 QProgressDialog
2564
2565 The QProgressDialog API has been significantly improved in Qt 4.
2566 The old \c QProgressDialog API is available as Q3ProgressDialog
2567 in the Qt3Support library.
2568
2569 See \l{#properties}{Properties} for a list of QProgressDialog
2570 properties in Qt 3 that have changed in Qt 4.
2571
2572 \section1 QPtrCollection<T>
2573
2574 The \c QPtrCollection<T> abstract base class has been renamed
2575 Q3PtrCollection<T> moved to the Qt3Support library.
2576 There is no direct equivalent in Qt 4.
2577
2578 \omit
2579 ###
2580 The QPtrCollection entry is unsatisfactory. The xref is missing
2581 its list and saying "no direct equivalent" with so suggestions
2582 seems feeble.
2583 \endomit
2584
2585 See \l{Generic Containers} for a list of Qt 4 containers.
2586
2587 \section1 QPtrDict<T>
2588
2589 \c QPtrDict<T> and \c QPtrDictIterator<T> have been renamed
2590 Q3PtrDict<T> and Q3PtrDictIterator<T> and have been moved to the
2591 Qt3Support library. They have been replaced by the
2592 more modern QHash<Key, T> and QMultiHash<Key, T> classes and
2593 their associated iterator classes.
2594
2595 When porting old code that uses Q3PtrDict<T> to Qt 4, there are
2596 four classes that you can use:
2597
2598 \list
2599 \o QMultiHash<void *, T *>
2600 \o QMultiHash<void *, T>
2601 \o QHash<void *, T *>
2602 \o QHash<void *, T>
2603 \endlist
2604
2605 (You can naturally use other types than \c{void *} for the key
2606 type, e.g. \c{QWidget *}.)
2607
2608 To port Q3PtrDict<T> to Qt 4, read the \l{#qdict.section}{section
2609 on QDict<T>}, mentally substituting \c{void *} for QString.
2610
2611 \target qptrlist.section
2612 \section1 QPtrList<T>
2613
2614 QPtrList<T>, QPtrListIterator<T>, and QPtrListStdIterator<T> have
2615 been moved to the Qt3Support library. They have been
2616 replaced by the more modern QList and QLinkedList classes and
2617 their associated iterator classes.
2618
2619 When porting to Qt 4, you have the choice of using QList<T> or
2620 QLinkedList<T> as alternatives to QValueList<T>. QList<T> has an
2621 index-based API and provides very fast random access
2622 (QList::operator[]), whereas QLinkedList<T> has an iterator-based
2623 API.
2624
2625 The following table summarizes the API differences between
2626 QPtrList<T> and QList<T *>:
2627
2628 \table
2629 \header \o QPtrList function \o QList equivalent
2630 \row \o QPtrList::contains(const T *) \o QList::count(T *)
2631 \row \o QPtrList::containsRef(const T *) \o QList::count(T *)
2632 \row \o QPtrList::find(const T *) \o See remark below
2633 \row \o QPtrList::findRef(const T *) \o See remark below
2634 \row \o QPtrList::getFirst() \o QList::first()
2635 \row \o QPtrList::getLast() \o QList::last()
2636 \row \o QPtrList::inSort(const T *) \o N/A
2637 \row \o QPtrList::remove(const T *) \o QList::removeAll(T *)
2638 \row \o QPtrList::remove(uint) \o QList::removeAt(int)
2639 \row \o QPtrList::removeNode(QLNode *) \o N/A
2640 \row \o QPtrList::removeRef(const T *) \o QList::removeAll(T *)
2641 \row \o QPtrList::sort() \o See remark below
2642 \row \o QPtrList::takeNode(QLNode *) \o N/A
2643 \row \o QPtrList::toVector(QGVector *) \o See remark below
2644 \endtable
2645
2646 Remarks:
2647
2648 \list 1
2649 \o QPtrList::toVector(QGVector *) can be replaced by
2650 QVector::resize() and qCopy().
2651
2652 \oldcode
2653 QPtrList<QWidget> list;
2654 ...
2655 QPtrVector<QWidget> vector;
2656 list.toVector(&vector);
2657 \newcode
2658 QList<QWidget *> list;
2659 ...
2660 QVector<QWidget *> vector;
2661 vector.resize(list.size());
2662 qCopy(list.begin(), list.end(), vector.begin());
2663 \endcode
2664
2665 \o QPtrList::sort() relied on the virtual compareItems() to
2666 sort items. In Qt 4, you can use \l qSort() instead and pass
2667 your "compare item" function as an argument.
2668
2669 \o QPtrList::find(const T *) returns an iterator, whereas
2670 QList::indexOf(T *) returns an index. To convert an index
2671 into an iterator, add the index to QList::begin().
2672
2673 \o QPtrList::removeFirst() and QPtrList::removeLast() return a \c
2674 bool that indicates whether the element was removed or not.
2675 The corresponding QList functions return \c void. You can
2676 achieve the same result by calling QList::isEmpty() before
2677 attempting to remove an item.
2678 \endlist
2679
2680 If you use QPtrList's auto-delete feature (by calling
2681 QPtrList::setAutoDelete(true)), you need to do some more work.
2682 You have two options: Either you call \c delete yourself whenever
2683 you remove an item from the container, or you can use QList<T>
2684 instead of QList<T *> (i.e. store values directly instead of
2685 pointers to values). Here, we'll see when to call \c delete.
2686
2687 \omit
2688 (See \l{What's Wrong with Auto-Delete} for an explanation of why
2689 the Qt 4 containers don't offer that feature.)
2690 \endomit
2691
2692 The following table summarizes the idioms that you need to watch
2693 out for if you want to call \c delete yourself.
2694
2695 \table
2696 \header \o QPtrList idiom \o QList idiom
2697 \row
2698 \o
2699 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 19
2700 \o
2701 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 20
2702 \row
2703 \o
2704 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 21
2705 \o
2706 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 22
2707 \row
2708 \o
2709 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 23
2710 \o
2711 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 24
2712 \row
2713 \o
2714 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 25
2715 \o
2716 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 26
2717 \row
2718 \o
2719 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 27
2720 \o
2721 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 28
2722 \row
2723 \o
2724 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 29
2725 (removes the current item)
2726
2727 \o
2728 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 30
2729 \row
2730 \o
2731 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 31
2732
2733 (also called from QPtrList's destructor)
2734
2735 \o
2736 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 32
2737
2738 In 99% of cases, the following idiom also works:
2739
2740 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 33
2741
2742 However, it may lead to crashes if \c list is referenced from
2743 the value type's destructor, because \c list contains
2744 dangling pointers until clear() is called.
2745 \endtable
2746
2747 Be aware that QPtrList's destructor automatically calls clear().
2748 If you have a QPtrList data member in a custom class and use the
2749 auto-delete feature, you will need to call \c delete on all the
2750 items in the container from your class destructor to avoid a
2751 memory leak.
2752
2753 QPtrList had the concept of a "current item", which could be used
2754 for traversing the list without using an iterator. When porting
2755 to Qt 4, you can use the Java-style QListIterator<T *> (or
2756 QMutableListIterator<T *>) class instead. The following table
2757 summarizes the API differences:
2758
2759 \table
2760 \header \o QPtrList function \o QListIterator equivalent
2761 \row \o QPtrList::at() \o N/A
2762 \row \o QPtrList::current() \o QMutableListIterator::value()
2763 \row \o QPtrList::currentNode() \o N/A
2764 \row \o QPtrList::findNext(const T *) \o QListIterator::findNext(const T *)
2765 \row \o QPtrList::findNextRef(const T *) \o QListIterator::findNext(const T *)
2766 \row \o QPtrList::first() \o QPtrList::toFront()
2767 \row \o QPtrList::last() \o QPtrList::toBack()
2768 \row \o QPtrList::next() \o QPtrList::next()
2769 \row \o QPtrList::prev() \o QPtrList::previous()
2770 \row \o QPtrList::remove() \o QMutableListIterator::remove()
2771 \row \o QPtrList::take() \o QMutableListIterator::remove()
2772 \endtable
2773
2774 Be aware that QListIterator has a different way of iterating than
2775 QPtrList. A typical loop with QPtrList looks like this:
2776
2777 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 34
2778
2779 Here's the equivalent QListIterator loop:
2780
2781 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 35
2782
2783 Finally, QPtrListIterator<T> must also be ported. There are no
2784 fewer than four iterator classes that can be used as a
2785 replacement: QList::const_iterator, QList::iterator,
2786 QListIterator, and QMutableListIterator. The most straightforward
2787 class to use when porting is QMutableListIterator<T *> (if you
2788 modify the list through the iterator) or QListIterator<T *> (if
2789 you don't). The following table summarizes the API differences:
2790
2791 \table
2792 \header \o QPtrListIterator function \o Qt 4 equivalent
2793 \row \o QPtrListIterator::atFirst() \o !QListIterator::hasPrevious() (notice the \c{!})
2794 \row \o QPtrListIterator::atLast() \o !QListIterator::hasNext() (notice the \c{!})
2795 \row \o QPtrListIterator::count() \o QList::count() or QList::size()
2796 \row \o QPtrListIterator::current() \o QMutableListIterator::value()
2797 \row \o QPtrListIterator::isEmpty() \o QList::isEmpty()
2798 \row \o QPtrListIterator::toFirst() \o QListIterator::toFront()
2799 \row \o QPtrListIterator::toLast() \o QListIterator::toBack()
2800 \row \o QPtrListIterator::operator() \o QMutableListIterator::value()
2801 \row \o QPtrListIterator::operator*() \o QMutableListIterator::value()
2802 \endtable
2803
2804 Again, be aware that QListIterator has a different way of
2805 iterating than QPtrList. A typical loop with QPtrList looks like
2806 this:
2807
2808 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 36
2809
2810 Here's the equivalent QListIterator loop:
2811
2812 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 37
2813
2814 Finally, QPtrListStdIterator<T> must also be ported. This is
2815 easy, because QList also provides STL-style iterators
2816 (QList::iterator and QList::const_iterator).
2817
2818 \section1 QPtrQueue<T>
2819
2820 QPtrQueue has been moved to the Qt3Support library.
2821 It has been replaced by the more modern QQueue class.
2822
2823 The following table summarizes the differences between
2824 QPtrQueue<T> and QQueue<T *>:
2825
2826 \table
2827 \header \o QPtrQueue function \o QQueue equivalent
2828 \row \o QPtrQueue::autoDelete() \o See discussion below
2829 \row \o QPtrQueue::count() \o QQueue::count() or QQueue::size() (equivalent)
2830 \row \o QPtrQueue::current() \o QQueue::head()
2831 \row \o QPtrQueue::remove() \o QQueue::dequeue()
2832 \row \o QPtrQueue::setAutoDelete() \o See discussion below
2833 \endtable
2834
2835 If you use QPtrQueue's auto-delete feature (by calling
2836 QPtrQueue::setAutoDelete(true)), you need to do some more work.
2837 You have two options: Either you call \c delete yourself whenever
2838 you remove an item from the container, or you can use QQueue<T>
2839 instead of QQueue<T *> (i.e. store values directly instead of
2840 pointers to values). Here, we will show when to call \c delete.
2841
2842 \omit
2843 (See \l{What's Wrong with Auto-Delete} for an explanation of why
2844 the Qt 4 containers don't offer that feature.)
2845 \endomit
2846
2847 \table
2848 \header \o QPtrQueue idiom \o QQueue idiom
2849 \row
2850 \o
2851 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 38
2852 \o
2853 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 39
2854 \row
2855 \o
2856 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 40
2857 \o
2858 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 41
2859 \row
2860 \o
2861 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 42
2862
2863 (also called from QPtrQueue's destructor)
2864
2865 \o
2866 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 43
2867
2868 In 99% of cases, the following idiom also works:
2869
2870 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 44
2871
2872 However, it may lead to crashes if \c queue is referenced
2873 from the value type's destructor, because \c queue contains
2874 dangling pointers until clear() is called.
2875 \endtable
2876
2877 \section1 QPtrStack<T>
2878
2879 QPtrStack has been moved to the Qt3Support library.
2880 It has been replaced by the more modern QStack class.
2881
2882 The following table summarizes the differences between
2883 QPtrStack<T> and QStack<T *>:
2884
2885 \table
2886 \header \o QPtrStack function \o QStack equivalent
2887 \row \o QPtrStack::autoDelete() \o See discussion below
2888 \row \o QPtrStack::count() \o QStack::count() or QStack::size() (equivalent)
2889 \row \o QPtrStack::current() \o QStack::top()
2890 \row \o QPtrStack::remove() \o QStack::pop()
2891 \row \o QPtrStack::setAutoDelete() \o See discussion below
2892 \endtable
2893
2894 If you use QPtrStack's auto-delete feature (by calling
2895 QPtrStack::setAutoDelete(true)), you need to do some more work.
2896 You have two options: Either you call \c delete yourself whenever
2897 you remove an item from the container, or you can use QStack<T>
2898 instead of QStack<T *> (i.e. store values directly instead of
2899 pointers to values). Here, we will show when to call \c delete.
2900
2901 \omit
2902 (See \l{What's Wrong with Auto-Delete} for an explanation of why
2903 the Qt 4 containers don't offer that feature.)
2904 \endomit
2905
2906 \table
2907 \header \o QPtrStack idiom \o QStack idiom
2908 \row
2909 \o
2910 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 45
2911 \o
2912 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 46
2913 \row
2914 \o
2915 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 47
2916 \o
2917 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 48
2918 \row
2919 \o
2920 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 49
2921
2922 (also called from QPtrStack's destructor)
2923
2924 \o
2925 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 50
2926
2927 In 99% of cases, the following idiom also works:
2928
2929 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 51
2930
2931 However, it may lead to crashes if \c stack is referenced
2932 from the value type's destructor, because \c stack contains
2933 dangling pointers until clear() is called.
2934 \endtable
2935
2936 \section1 QPtrVector<T>
2937
2938 QPtrVector<T> has been moved to Qt3Support. It has been replaced
2939 by the more modern QVector class.
2940
2941 When porting to Qt 4, you can use QVector<T *> as an alternative
2942 to QPtrVector<T>. The APIs of QPtrVector<T> and QVector<T *> are
2943 somewhat similar. The main issue is that QPtrVector supports
2944 auto-delete whereas QVector doesn't.
2945
2946 \omit
2947 (See \l{What's Wrong with Auto-Delete} for an explanation of why
2948 the Qt 4 containers don't offer that feature.)
2949 \endomit
2950
2951 The following table summarizes the API differences between the
2952 two classes:
2953
2954 \table
2955 \header \o QPtrVector function \o QVector equivalent
2956 \row \o QPtrVector::autoDelete() \o See discussion below
2957 \row \o QPtrVector::bsearch(const T *) \o \l qBinaryFind()
2958 \row \o QPtrVector::contains(const T *) \o QVector::count(T *)
2959 \row \o QPtrVector::containsRef(const T *) \o QVector::count(T *)
2960 \row \o QPtrVector::count() \o See remark below
2961 \row \o QPtrVector::insert(uint, T *) \o See remark below
2962 \row \o QPtrVector::isNull() \o N/A
2963 \row \o QPtrVector::remove(uint) \o See remark below
2964 \row \o QPtrVector::setAutoDelete() \o See discussion below
2965 \row \o QPtrVector::sort() \o \l qSort()
2966 \row \o QPtrVector::take(uint) \o See remark below
2967 \row \o QPtrVector::toList(QGList *) \o QList::QList(const QVector &)
2968 \endtable
2969
2970 Remarks:
2971
2972 \list 1
2973 \o QPtrVector::insert(uint, T *) sets an item to store a certain
2974 pointer value. This is \e not the same as QVector::insert(int, T *),
2975 which creates space for the item by moving following items by
2976 one position. Use \c{vect[i] = ptr} to set a QVector item to
2977 a particular value.
2978 \o QPtrVector::remove(uint) sets an item to be 0. This is \e not
2979 the same as QVector::removeAt(int), which entirely erases the
2980 item, reducing the size of the vector. Use \c{vect[i] = 0} to
2981 set a QVector item to 0.
2982 \o Likewise, QPtrVector::take(uint) sets an item to be 0 and
2983 returns the previous value of the item. Again, this is easy to
2984 achieve using QVector::operator[]().
2985 \o QPtrVector::count() returns the number of non-null items in
2986 the vector, whereas QVector::count() (like QVector::size())
2987 returns the number of items (null or non-null) in the vector.
2988 Fortunately, it's not too hard to simulate QPtrVector::count().
2989
2990 \oldcode
2991 int numValidItems = vect.count();
2992 \newcode
2993 int numValidItems = vect.size() - vect.count(0);
2994 \endcode
2995 \endlist
2996
2997 If you use QVector's auto-delete feature (by calling
2998 QVector::setAutoDelete(true)), you need to do some more work. You
2999 have two options: Either you call \c delete yourself whenever you
3000 remove an item from the container, or you use QVector<T> instead
3001 of QVector<T *> (i.e. store values directly instead of pointers
3002 to values). Here, we'll see when to call \c delete.
3003
3004 The following table summarizes the idioms that you need to watch
3005 out for if you want to call \c delete yourself.
3006
3007 \table
3008 \header \o QPtrVector idiom \o QVector idiom
3009 \row
3010 \o
3011 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 52
3012 \o
3013 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 53
3014 \row
3015 \o
3016 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 54
3017 \o
3018 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 55
3019 \row
3020 \o
3021 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 56
3022 \o
3023 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 57
3024 \row
3025 \o
3026 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 58
3027 \o
3028 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 59
3029 \row
3030 \o
3031 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 60
3032
3033 (also called from QPtrVector's destructor)
3034
3035 \o
3036 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 61
3037
3038 In 99% of cases, the following idiom also works:
3039
3040 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 62
3041
3042 However, it may lead to crashes if \c vect is referenced from
3043 the value type's destructor, because \c vect contains
3044 dangling pointers until clear() is called.
3045 \endtable
3046
3047 Be aware that QPtrVector's destructor automatically calls
3048 clear(). If you have a QPtrVector data member in a custom class
3049 and use the auto-delete feature, you will need to call \c delete
3050 on all the items in the container from your class destructor to
3051 avoid a memory leak.
3052
3053 \section1 QPushButton
3054
3055 See \l{#properties}{Properties} for a list of QPushButton
3056 properties in Qt 3 that have changed in Qt 4.
3057
3058 \section1 QRangeControl
3059
3060 In Qt 3, various "range control" widgets (QDial, QScrollBar,
3061 QSlider, and QSpin) inherited from both QWidget and
3062 \c QRangeControl.
3063
3064 In Qt 4, \c QRangeControl has been replaced with the new
3065 QAbstractSlider and QAbstractSpinBox classes, which inherit from
3066 QWidget and provides similar functionality. Apart from eliminating
3067 unnecessary multiple inheritance, the new design allows
3068 QAbstractSlider to provide signals, slots, and properties.
3069
3070 The old \c QRangeControl class has been renamed Q3RangeControl
3071 and moved to the Qt3Support library, together with
3072 the (undocumented) \c QSpinWidget class.
3073
3074 If you use \c QRangeControl as a base class in your application,
3075 you can switch to use QAbstractSlider or QAbstractSpinBox instead.
3076
3077 \oldcode
3078 class VolumeControl : public QWidget, public QRangeControl
3079 {
3080 ...
3081 protected:
3082 void valueChange() {
3083 update();
3084 emit valueChanged(value());
3085 }
3086 void rangeChange() {
3087 update();
3088 }
3089 void stepChange() {
3090 update();
3091 }
3092 };
3093 \newcode
3094 class VolumeControl : public QAbstractSlider
3095 {
3096 ...
3097 protected:
3098 void sliderChange(SliderChange change) {
3099 update();
3100 if (change == SliderValueChange)
3101 emit valueChanged(value());
3102 }
3103 };
3104 \endcode
3105
3106 \section1 QRegExp
3107
3108 The search() and searchRev() functions have been renamed to indexIn()
3109 and lastIndexIn() respectively.
3110
3111 \section1 QRegion
3112
3113 The following changes have been made to QRegion in Qt 4:
3114
3115 \list
3116 \o There is no longer any difference between a \e null region and
3117 an \e empty region. Use isEmpty() in most places where you
3118 would have used a null QRegion.
3119 \o QRegion::rects() used to return a QMemArray<QRect>. It now returns
3120 a QVector<QRect>.
3121 \endlist
3122
3123 \section1 QScrollBar
3124
3125 See \l{#properties}{Properties} for a list of QScrollBar
3126 properties in Qt 3 that have changed in Qt 4.
3127
3128 \section1 QScrollView
3129
3130 The \c QScrollView class has been renamed Q3ScrollView and moved
3131 to the Qt3Support library. It has been replaced by
3132 the QAbstractScrollArea and QScrollArea classes.
3133
3134 Note that Qt 4 in general uses the QScrollArea::widget() function
3135 where Qt 3 used QScrollView::viewport(). The rationale for this is
3136 that it is no longer possible to draw directly on a scroll
3137 area. The QScrollArea::widget() function returns the widget set on
3138 the scroll area.
3139
3140 \c QScrollView was designed to work around the 16-bit limitation
3141 on widget coordinates found on most window systems. In Qt 4, this
3142 is done transparently for \e all widgets, so there is no longer a
3143 need for such functionality in \c QScrollView. For that reason,
3144 the new QAbstractScrollArea and QScrollArea classes are much more
3145 lightweight, and concentrate on handling scroll bars.
3146
3147 \section1 QServerSocket
3148
3149 The \c QServerSocket class has been renamed Q3ServerSocket and
3150 moved to the Qt3Support library. In Qt 4, it has been
3151 replaced by QTcpServer.
3152
3153 With Q3ServerSocket, connections are accepted by reimplementing a
3154 virtual function (Q3ServerSocket::newConnection()). With
3155 QTcpServer, on the other hand, you don't need to subclass.
3156 Instead, simply connect to the QTcpServer::newConnection()
3157 signal.
3158
3159 \section1 QSettings
3160
3161 The QSettings class has been rewritten to be more robust and to
3162 respect existing standards (e.g., the INI file format). The API
3163 has also been extensively revised. The old API is still provided
3164 when Qt 3 support is enabled.
3165
3166 Since the format and location of settings have changed between Qt
3167 3 and Qt 4, the Qt 4 version of your application won't recognize
3168 settings written using Qt 3.
3169
3170 \section1 QShared
3171
3172 The \c QShared class has been obsoleted by the more powerful
3173 QSharedData and QSharedDataPointer as a means of creating custom
3174 implicitly shared classes. It has been renamed Q3Shared moved to
3175 the Qt3Support library.
3176
3177 An easy way of porting to Qt 4 is to include this class into your
3178 project and to use it instead of \c QShared:
3179
3180 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 63
3181
3182 If possible, we recommend that you use QSharedData and
3183 QSharedDataPointer instead. They provide thread-safe reference
3184 counting and handle all the reference counting behind the scenes,
3185 eliminating the risks of forgetting to increment or decrement the
3186 reference count.
3187
3188 \section1 QSignal
3189
3190 The QSignal class has been renamed to Q3Signal and moved to the
3191 Qt3Support library. The preferred approach is to create your own
3192 QObject subclass with a signal that has the desired signature.
3193 Alternatively, you can call QMetaObject::invokeMethod() if you
3194 want to invoke a slot.
3195
3196 \section1 QSimpleRichText
3197
3198 QSimpleRichText has been obsoleted by QTextDocument. It has
3199 bene renamed Q3SimpleRichText and moved to the Qt3Support
3200 library.
3201
3202 Previously, you would do the following with Q3SimpleRichText:
3203
3204 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 63a
3205
3206 However, with QTextDocument, you use the following code instead:
3207
3208 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 63b
3209
3210 See \l{Rich Text Processing} for an overview of the Qt 4 rich
3211 text classes.
3212
3213 \section1 QSlider
3214
3215 The QSlider::sliderStart() and QSlider::sliderRect() functions
3216 have been removed.
3217
3218 The slider's rect can now be retrieved using the code snippet below:
3219
3220 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 63c
3221
3222 In addition, the direction of a vertical QSlider has changed,
3223 i.e. the bottom is now the minimum, and the top the maximum. You
3224 can use the QAbstractSlider::invertedAppearance property to
3225 control this behavior.
3226
3227 See \l{#properties}{Properties} for a list of QSlider properties
3228 in Qt 3 that have changed in Qt 4.
3229
3230 \section1 QSocket
3231
3232 The \c QSocket class has been renamed Q3Socket and moved to the
3233 Qt3Support library. In Qt 4, it has been replaced by
3234 the QTcpSocket class, which inherits most of its functionality
3235 from QAbstractSocket.
3236
3237 \section1 QSocketDevice
3238
3239 The \c QSocketDevice class has been renamed Q3SocketDevice and
3240 moved to the Qt3Support library. In Qt 4, there is no
3241 direct equivalent to Q3SocketDevice:
3242
3243 \list
3244 \o If you use Q3SocketDevice in a thread to perform blocking network
3245 I/O (a technique encouraged by the \e{Qt Quarterly} article
3246 \l{http://doc.trolltech.com/qq/qq09-networkthread.html}{Unblocking Networking}),
3247 you can now use QTcpSocket, QFtp, or QHttp instead, which can now be used from
3248 non-GUI threads.
3249
3250 \o If you use Q3SocketDevice for UDP, you can now use QUdpSocket instead.
3251
3252 \o If you use Q3SocketDevice for other uses, Qt 4 offers no
3253 alternative right now. However, there is a \c QAbstractSocketEngine
3254 internal class that offers a low-level socket API similar to
3255 Q3SocketDevice. Should the need for such functionality arise in
3256 Qt 4 applications, we will consider making this class public in a
3257 future release.
3258 \endlist
3259
3260 \section1 QSortedList
3261
3262 The QSortedList<T> class has been deprecated since Qt 3.0. In Qt
3263 4, it has been moved to the Qt3Support library.
3264
3265 In new code, we recommend that you use QList<T> instead and use
3266 \l qSort() to sort the items.
3267
3268 \section1 QSplitter
3269
3270 The function setResizeMode() has been moved into Qt3Support. Set
3271 the stretch factor in the widget's size policy to get equivalent
3272 functionality.
3273
3274 The obsolete function drawSplitter() has been removed. Use
3275 QStyle::drawPrimitive() to acheive similar functionality.
3276
3277 \section1 QSpinBox
3278
3279 See \l{#properties}{Properties} for a list of QSpinBox properties
3280 in Qt 3 that have changed in Qt 4.
3281
3282 \section1 QSqlCursor
3283
3284 The \c QSqlCursor class has been renamed Q3SqlCursor and moved to
3285 the Qt3Support library. In Qt 4, you can use
3286 QSqlQuery, QSqlQueryModel, or QSqlTableModel, depending on
3287 whether you want a low-level or a high-level interface for
3288 accessing databases.
3289
3290 See \l{QtSql Module} for an overview of the new SQL classes.
3291
3292 \section1 QSqlDatabase
3293
3294 QSqlDatabase is now a smart pointer that is passed around by
3295 value. Simply replace all QSqlDatabase pointers by QSqlDatabase
3296 objects.
3297
3298 \section1 QSqlEditorFactory
3299
3300 The \c QSqlEditorFactory class has been renamed
3301 Q3SqlEditorFactory and moved to Qt3Support.
3302
3303 See \l{QtSql Module} for an overview of the new SQL classes.
3304
3305 \section1 QSqlError
3306
3307 The enum \c{Type} was renamed to \c{ErrorType}, The values were renamed as well:
3308
3309 \list
3310 \o None - use NoError instead
3311 \o Connection - use ConnectionError instead
3312 \o Statement - use StatementError instead
3313 \o Transaction - use TransactionError instead
3314 \o Unknown - use UnknownError instead
3315 \endlist
3316
3317 \section1 QSqlFieldInfo
3318
3319 The QSqlFieldInfo class has been moved to Qt3Support. Its
3320 functionality is now provided by the QSqlField class.
3321
3322 See \l{QtSql Module} for an overview of the new SQL classes.
3323
3324 \section1 QSqlForm
3325
3326 The \c QSqlForm class has been renamed Q3SqlForm and moved to the
3327 Qt3Support library.
3328
3329 See \l{QtSql Module} for an overview of the new SQL classes.
3330
3331 \section1 QSqlPropertyMap
3332
3333 The \c QSqlPropertyMap class has been renamed Q3SqlPropertyMap
3334 moved to the Qt3Support library.
3335
3336 See \l{QtSql Module} for an overview of the new SQL classes.
3337
3338 \section1 QSqlQuery
3339
3340 QSqlQuery::prev() was renamed to QSqlQuery::previous().
3341 QSqlQuery::prev() remains, but it just calls previous().
3342 QSqlQuery no longer has any virtual methods, i.e., exec(),
3343 value(), seek(), next(), prev(), first(), last(), and the
3344 destructor are no longer virtual.
3345
3346 \section1 QSqlRecord
3347
3348 QSqlRecord behaves like a vector now, QSqlRecord::insert() will
3349 actually insert a new field instead of replacing the existing
3350 one.
3351
3352 \section1 QSqlRecordInfo
3353
3354 The QSqlRecordInfo class has been moved to Qt3Support. Its
3355 functionality is now provided by the QSqlRecord class.
3356
3357 See \l{QtSql Module} for an overview of the new SQL classes.
3358
3359 \section1 QSqlSelectCursor
3360
3361 The \c QSqlSelectCursor class has been renamed Q3SqlSelectCursor
3362 and moved to the Qt3Support library.
3363
3364 See \l{QtSql Module} for an overview of the new SQL classes.
3365
3366 \section1 QStoredDrag
3367
3368 The \c QStoredDrag class has been renamed Q3StoredDrag and moved
3369 to the Qt3Support library. In Qt 4, use QMimeData
3370 instead and call QMimeData::setData() to set the data.
3371
3372 See \l{Porting to Qt 4 - Drag and Drop} for a comparison between
3373 the drag and drop APIs in Qt 3 and Qt 4.
3374
3375 \section1 QStr(I)List
3376
3377 The QStrList and QStrIList convenience classes have been
3378 deprecated since Qt 2.0. In Qt 4, they have been moved to the
3379 Qt3Support library. If you used any of these, we
3380 recommend that you use QStringList or QList<QByteArray> instead.
3381
3382 \section1 QStr(I)Vec
3383
3384 The QStrVec and QStrIVec convenience classes have been deprecated
3385 since Qt 2.0. In Qt 4, they have been moved to Qt3Support. If you
3386 used any of these, we recommend that you use QStringList or
3387 QList<QByteArray> instead.
3388
3389 \section1 QString
3390
3391 Here are the main issues to be aware of when porting QString to
3392 Qt 4:
3393
3394 \list 1
3395 \o The QString::QString(QChar) constructor performed implicit
3396 conversion in Qt 3. Now, you will need a cast to convert a
3397 QChar to a QString.
3398
3399 \o The QString::QString(const QByteArray &) constructor used to
3400 stop at the first '\\0' it encountered, for compatibility
3401 with Qt 1. This quirk has now been fixed; in Qt 4, the
3402 resulting QString always has the same length as the
3403 QByteArray that was passed to the constructor.
3404
3405 \o The QString::null static constant has been deprecated in Qt
3406 4. For compatibility, Qt 4 provides a QString::null symbol
3407 that behaves more or less the same as the old constant. The
3408 new idiom is to write QString() instead of QString::null, or
3409 to call clear().
3410
3411 \oldcode
3412 str1 = QString::null;
3413 if (str2 == QString::null)
3414 do_something(QString::null);
3415 \newcode
3416 str1.clear();
3417 if (str2.isNull())
3418 do_something(QString());
3419 \endcode
3420
3421 In new code, we recommend that you don't rely on the
3422 distinction between a null string and a (non-null) empty
3423 string. See \l{Distinction Between Null and Empty Strings}
3424 for details.
3425
3426 \o QString::latin1() and QString::ascii() have been replaced
3427 with QString::toLatin1() and QString::toAscii(), which return
3428 a QByteArray instead of a (non-reentrant) \c{const char *}.
3429 For consistency, QString::utf8() and QString::local8Bit(),
3430 which already returned a QByteArray (actually a \c QCString),
3431 have been renamed QString::toUtf8() and
3432 QString::toLocal8Bit().
3433
3434 To obtain a \c{const char *} pointer to ASCII or Latin-1 data,
3435 use QString::toAscii() or QString::toLatin1() to obtain a
3436 QByteArray containing the data, then call QByteArray::constData()
3437 to access the character data directly. Note that the pointer
3438 returned by this function is only valid for the lifetime of the
3439 byte array; you should avoid taking a pointer to the data
3440 contained in temporary objects.
3441
3442 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 64
3443
3444 In the above example, the \c goodData pointer is valid for the lifetime
3445 of the \c asciiData byte array. If you need to keep a copy of the data
3446 in a non-Qt data structure, use standard C memory allocation and string
3447 copying functions to do so \e before destroying the byte array.
3448
3449 \o QString::at() returned a non-const reference, whereas the
3450 new QString::at() returns a const value. Code like
3451
3452 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 65
3453
3454 will no longer compile. Instead, use QString::operator[]:
3455
3456 \snippet doc/src/snippets/code/doc_src_porting4.qdoc 66
3457
3458 \o The QString::contains(\e x) function (where \e x is a
3459 character or a string) has been renamed QString::count(\e x).
3460 In addition, there now exists a set of QString::contains()
3461 functions that returns a boolean value. Replace old calls to
3462 contains() with either count() or contains(), depending on
3463 whether you care about the specific number of occurrences of
3464 a character in the string or only care about whether the
3465 string contains that character or not.
3466
3467 \o Many functions in QString had a \c bool parameter that
3468 specified case sensitivity. In Qt 4, in the interest of code
3469 readability and maintainability, the \c bool parameters have
3470 been replaced by the Qt::CaseSensitivity enum, which can take
3471 the values Qt::CaseSensitive and Qt::CaseInsensitive.
3472
3473 \oldcode
3474 if (url.startsWith("http:", false))
3475 ...
3476 \newcode
3477 if (url.startsWith("http:", Qt::CaseInsensitive))
3478 ...
3479 \endcode
3480
3481 \o The QString::setExpand(uint, QChar) function, which already
3482 was obsolete in Qt 3, is no longer available. Use
3483 QString::operator[] instead.
3484
3485 \oldcode
3486 str.setExpand(32, '$');
3487 \newcode
3488 str[32] = '$';
3489 \endcode
3490
3491 \o The \c QT_NO_ASCII_CAST and \c QT_NO_CAST_ASCII macros have
3492 been renamed \c QT_NO_CAST_TO_ASCII and \c
3493 QT_NO_CAST_FROM_ASCII, respectively.
3494
3495 \o The QString::data() used to return the same as
3496 QString::ascii(). It now returns a pointer to the Unicode
3497 data stored in the QString object. Call QString::ascii() if
3498 you want the old behavior.
3499
3500 \o QString::arg() now converts two-digit place markers, allowing
3501 up to 99 place markers to be used in any given string.
3502
3503 \o Comparisons between QStrings and \c NULL in order to determine
3504 whether strings are empty are no longer allowed.
3505 Use \l{QString::}{isEmpty()} instead.
3506
3507 \endlist
3508
3509 \section1 QStringList
3510
3511 QStringList now inherits from QList<QString> and can no longer be
3512 converted to a QValueList<QString>. Since QValueList inherits QList a
3513 cast will work as expected.
3514
3515 This change implies some API incompatibilities for QStringList.
3516 For example, at() returns the string, not an iterator. See the
3517 \l{#qvaluelist.section}{section on QValueList} for details.
3518
3519 The static QStringList::split() function for splitting strings into
3520 lists of smaller strings has been replaced by QString::split(),
3521 which returns a QStringList.
3522
3523 \section1 QStyle
3524
3525 The QStyle API has been overhauled and improved. Most of the information on
3526 why this change was done is described in \l{The Qt 4 Style API}{the QStyle overview}.
3527
3528 Since QStyle is mostly used internally by Qt's widgets and styles and since
3529 it is not essential to the good functioning of an application, there is no
3530 compatibility path. This means that we have changed many enums and
3531 functions and the qt3to4 porting tool will not change much in your qstyle
3532 code. To ease the pain, we list some of the major changes here.
3533
3534 QStyleOption has taken on a more central role and is no longer an optional
3535 argument, please see the QStyleOption documentation for more information.
3536
3537 The QStyle::StyleFlags have been renamed QStyle::StateFlags and are now prefixed State_
3538 instead of Style_, in addition the Style_ButtonDefault flag has moved to
3539 QStyleOptionButton.
3540
3541 The QStyle::PrimitiveElement enumeration has undergone extensive change.
3542 Some of the enums were moved to QStyle::ControlElement, some were removed
3543 and all were renamed. This renaming is not done by the qt3to4 porting tool,
3544 so you must do it yourself. The table below shows how things look
3545 now.
3546
3547 \table
3548 \header \o Old name \o New name \o Remark
3549 \row \o \c PE_ButtonCommand \o QStyle::PE_PanelButtonCommand
3550 \row \o \c PE_ButtonDefault \o QStyle::PE_FrameDefaultButton
3551 \row \o \c PE_ButtonBevel \o QStyle::PE_PanelButtonBevel
3552 \row \o \c PE_ButtonTool \o QStyle::PE_PanelButtonTool
3553 \row \o \c PE_ButtonDropDown \o QStyle::PE_IndicatorButtonDropDown
3554 \row \o \c PE_FocusRect \o QStyle::PE_FrameFocusRect
3555 \row \o \c PE_ArrowUp \o QStyle::PE_IndicatorArrowUp
3556 \row \o \c PE_ArrowDown \o QStyle::PE_IndicatorArrowDown
3557 \row \o \c PE_ArrowRight \o QStyle::PE_IndicatorArrowRight
3558 \row \o \c PE_ArrowLeft \o QStyle::PE_IndicatorArrowLeft
3559 \row \o \c PE_SpinBoxUp \o QStyle::PE_IndicatorSpinUp
3560 \row \o \c PE_SpinBoxDown \o QStyle::PE_IndicatorSpinDown
3561 \row \o \c PE_SpinBoxPlus \o QStyle::PE_IndicatorSpinPlus
3562 \row \o \c PE_SpinBoxMinus \o QStyle::PE_IndicatorSpinMinus
3563 \row \o \c PE_SpinBoxSlider \o QStyle::CE_SpinBoxSlider \o uses QStyle::drawControl()
3564 \row \o \c PE_Indicator \o QStyle::PE_IndicatorCheckBox
3565 \row \o \c PE_IndicatorMask \o N/A \o use QStyle::styleHint() to retrieve mask
3566 \row \o \c PE_ExclusiveIndicator \o QStyle::PE_IndicatorRadioButton
3567 \row \o \c PE_ExclusiveIndicatorMask \o N/A \o use QStyle::styleHint() to retrieve mask
3568 \row \o \c PE_DockWindowHandle \o QStyle::PE_IndicatorToolBarHandle
3569 \row \o \c PE_DockWindowSeparator \o QStyle::PE_Q3DockWindowSeparator
3570 \row \o \c PE_DockWindowResizeHandle \o QStyle::PE_IndicatorDockWindowResizeHandle
3571 \row \o \c PE_DockWindowTitle \o QStyle::CE_DockWindowTitle \o uses QStyle::drawControl()
3572 \row \o \c PE_Splitter \o QStyle::CE_Splitter \o uses QStyle::drawControl()
3573 \row \o \c PE_Panel \o QStyle::PE_Frame
3574 \row \o \c PE_PanelMenu \o QStyle::PE_FrameMenu
3575 \row \o \c PE_PanelMenuBar \o QStyle::PE_PanelMenuBar
3576 \row \o \c PE_PanelDockWindow \o QStyle::PE_FrameDockWindow
3577 \row \o \c PE_TabBarBase \o QStyle::PE_FrameTabBarBase
3578 \row \o \c PE_HeaderSection \o QStyle::CE_HeaderSection \o uses QStyle::drawControl()
3579 \row \o \c PE_HeaderArrow \o QStyle::PE_IndicatorHeaderArrow
3580 \row \o \c PE_StatusBarSection \o QStyle::PE_FrameStatusBar
3581 \row \o \c PE_Separator \o QStyle::PE_Q3Separator
3582 \row \o \c PE_SizeGrip \o QStyle::CE_SizeGrip \o uses QStyle::drawControl()
3583 \row \o \c PE_CheckMark \o QStyle::PE_IndicatorMenuCheckMark
3584 \row \o \c PE_ScrollBarAddLine \o QStyle::CE_ScrollBarAddLine \o uses QStyle::drawControl()
3585 \row \o \c PE_ScrollBarSubLine \o QStyle::CE_ScrollBarSubLine \o uses QStyle::drawControl()
3586 \row \o \c PE_ScrollBarAddPage \o QStyle::CE_ScrollBarAddPage \o uses QStyle::drawControl()
3587 \row \o \c PE_ScrollBarSubPage \o QStyle::CE_ScrollBarSubPage \o uses QStyle::drawControl()
3588 \row \o \c PE_ScrollBarSlider \o QStyle::CE_ScrollBarSlider \o uses QStyle::drawControl()
3589 \row \o \c PE_ScrollBarFirst \o QStyle::CE_ScrollBarFirst \o uses QStyle::drawControl()
3590 \row \o \c PE_ScrollBarLast \o QStyle::CE_ScrollBarLast \o uses QStyle::drawControl()
3591 \row \o \c PE_ProgressBarChunk \o QStyle::PE_IndicatorProgressChunk
3592 \row \o \c PE_PanelLineEdit \o QStyle::PE_FrameLineEdit
3593 \row \o \c PE_PanelTabWidget \o QStyle::PE_FrameTabWidget
3594 \row \o \c PE_WindowFrame \o QStyle::PE_FrameWindow
3595 \row \o \c PE_CheckListController \o QStyle::PE_Q3CheckListController
3596 \row \o \c PE_CheckListIndicator \o QStyle::PE_Q3CheckListIndicator
3597 \row \o \c PE_CheckListExclusiveIndicato\o QStyle::PE_Q3CheckListExclusiveIndicator
3598 \row \o \c PE_PanelGroupBox \o QStyle::PE_FrameGroupBox
3599 \row \o \c PE_TreeBranch \o QStyle::PE_IndicatorBranch
3600 \row \o \c PE_RubberBand \o QStyle::CE_RubberBand \o uses QStyle::drawControl()
3601 \row \o \c PE_PanelToolBar \o QStyle::PE_PanelToolBar
3602 \row \o \c PE_ToolBarHandle \o QStyle::PE_IndicatorToolBarHandle
3603 \row \o \c PE_ToolBarSeparator \o QStyle::PE_IndicatorToolBarSeparator
3604 \endtable
3605
3606 The QStyle::drawControlMask() and QStyle::drawComplexControlMask()
3607 functions have been removed. They are replaced with a style hint.
3608
3609 The QStyle::drawItem() overloads that took both a pixmap and a string have
3610 been removed. Use QStyle::drawItemText() and QStyle::drawItemPixmap() directly.
3611
3612 The QStyle::itemRect() overload that took both a pixmap and a string is also removed, use
3613 either QStyle::itemTextRect() or QStyle::itemPixmapRect() instead.
3614
3615 \section1 QStyleSheet
3616
3617 The QStyleSheet and QStyleSheetItem classes have been renamed
3618 Q3StyleSheet and Q3StyleSheetItem, and have been moved to the
3619 Qt3Support library.
3620
3621 See \l{Rich Text Processing} for an overview of the Qt 4 rich
3622 text classes, and \l{Qt Style Sheets} for a description of
3623 CSS-like style sheet support in Qt 4.2 and above.
3624
3625 \section1 QSyntaxHighlighter
3626
3627 The \c QSyntaxHighlighter class from Qt 3 has been renamed
3628 Q3SyntaxHighlighter and moved to the Qt3Support library. Since Qt
3629 4.1, it has been replaced by a new QSyntaxHighlighter class based
3630 on Qt 4's new rich text engine.
3631
3632 \section1 QTabBar
3633
3634 See \l{#properties}{Properties} for a list of QTabBar properties
3635 in Qt 3 that have changed in Qt 4.
3636
3637 \section1 QTabDialog
3638
3639 The \c QTabDialog class is no longer part of the public Qt API.
3640 It has been renamed Q3TabDialog and moved to Qt3Support. In Qt 4
3641 applications, you can easily obtain the same result by combining
3642 a QTabWidget with a QDialog and provide \l{QPushButton}s
3643 yourself.
3644
3645 See also the \l{dialogs/tabdialog} example, which shows how to
3646 implement tab dialogs in Qt 4.
3647
3648 \section1 QTabWidget
3649
3650 See \l{#properties}{Properties} for a list of QTabWidget
3651 properties in Qt 3 that have changed in Qt 4.
3652
3653 \section1 QTable
3654
3655 The \c QTable, \c QTableItem, \c QComboTableItem, \c
3656 QCheckTableItem, and \c QTableSelection classes have been renamed
3657 Q3Table, Q3TableItem, Q3ComboTableItem, Q3CheckTableItem, and
3658 Q3TableSelection and moved to the Qt3Support library.
3659 New Qt applications should use the new QTableWidget or QTableView
3660 class instead.
3661
3662 Some of these classes behave differently with respect to the way
3663 they handle \c NULL pointers. For example, Q3TableItem::setPixmap()
3664 no longer accepts \c NULL or 0 to indicate that the item should
3665 contain a null pixmap; in this case, a null pixmap should be
3666 constructed and passed explicitly to the function.
3667
3668 See \l{Model/View Programming} for an overview of the new item
3669 view classes.
3670
3671 \section1 QTextCodec
3672
3673 The loadCharmap() and loadCharmapFromFile() functions are no longer
3674 available in Qt 4. You need to create your own codec if you want to
3675 create a codec based on a POSIX2 charmap definition.
3676
3677 \section1 QTextDrag
3678
3679 The \c QTextDrag class has been renamed Q3TextDrag and moved to
3680 the Qt3Support library. In Qt 4, use QMimeData
3681 instead and call QMimeData::setText() to set the data.
3682
3683 See \l{Porting to Qt 4 - Drag and Drop} for a comparison between
3684 the drag and drop APIs in Qt 3 and Qt 4.
3685
3686 \section1 QTextEdit
3687
3688 The old QTextEdit and QTextBrowser classes have been renamed
3689 Q3TextEdit and Q3TextBrowser, and have been moved to Qt3Support.
3690 The new QTextEdit and QTextBrowser have a somewhat different API.
3691
3692 The \c QTextEdit::setWrapPolicy() function has been renamed to \l{QTextEdit::setWordWrapMode()}{setWordWrapMode()} and the
3693 \c QTextEdit::setWrapColumnOrWidth() function has been renamed to \l{QTextEdit::setLineWrapColumnOrWidth()}
3694 {setLineWrapColumnOrWidth()}. The Q3TextEdit::setWrapPolicy() and Q3TextEdit::setWrapColumnOrWidth() still provide this
3695 functionality in the Q3TextEdit class.
3696
3697
3698 See \l{Rich Text Processing} for an overview of the Qt 4 rich
3699 text classes.
3700
3701 \section1 QTextIStream
3702
3703 The QTextIStream convenience class is no longer provided in Qt 4. Use
3704 QTextStream directly instead.
3705
3706 \section1 QTextOStream
3707
3708 The QTextOStream convenience class is no longer provided in Qt 4. Use
3709 QTextStream directly instead.
3710
3711 \section1 QTextOStreamIterator
3712
3713 The undocumented \c QTextOStreamIterator class has been removed
3714 from the Qt library. If you need it in your application, feel
3715 free to copy the source code from the Qt 3 \c <qtl.h> header
3716 file.
3717
3718 \section1 QTextStream
3719
3720 QTextStream has undergone a number of API and implementation enhancements,
3721 and some of the changes affect QTextStream's behavior:
3722
3723 \list
3724 \o QTextStream now uses buffered writing, which means that you need to
3725 call QTextStream::flush(), or use the streaming manipulators \c endl or
3726 \c flush if you need QTextStream to flush its write buffer. The stream is
3727 flushed automatically if QTextStream is deleted or when the device is
3728 closed.
3729 \o QTextStream now uses buffered reading, so if you read a line from the
3730 stream, QTextStream will read as much as it can from the device to
3731 fill up its internal read buffer. This speeds up reading significantly,
3732 but Qt 3 code that mixed QTextStream access and direct device access
3733 may need to be updated.
3734 \o While QTextStream in Qt 3 always translated end-of-line characters from
3735 Windows style ("\\r\\n") to Unix style ("\\n") on Windows, QTextStream in
3736 Qt 4 only does this on devices opened with the \c{QIODevice::Text} mode
3737 (formerly \c{IO_Translate}).
3738 \endlist
3739
3740 Note that when using a QTextStream on a QFile in Qt 4, calling
3741 QIODevice::reset() on the QFile will not have the expected result
3742 because QTextStream now buffers the file. Use the
3743 QTextStream::seek() function instead.
3744
3745 \section1 QTextView
3746
3747 The \c QTextView class has been renamed Q3TextView and moved to the
3748 Qt3Support library.
3749
3750 \section1 QTimeEdit
3751
3752 The QTimeEdit class in Qt 4 is a convenience class based on
3753 QDateTimeEdit. The old class has been renamed Q3TimeEdit and moved
3754 to the Qt3Support library.
3755
3756 See \l{Porting to Qt 4 - Virtual Functions}{Virtual Functions} for
3757 a list of \c QTimeEdit virtual member functions in Qt 3 that are no
3758 longer virtual in Qt 4.
3759
3760 \section1 QTimer
3761
3762 Windows restricts the granularity of timers, but starting with Qt 4,
3763 we emulate a finer time resolution. On Windows XP we use the
3764 multimedia timer API, which gives us 1 millisecond resolution for
3765 QTimer.
3766
3767 Note that other versions of Windows have a lower timer resolution,
3768 and that code relying on underlying system timer restrictions
3769 encounters no such limitations using Qt 4 (e.g., setting an
3770 interval of 0 millisecond results in Qt occupying all of the
3771 processor time when no GUI events need processing).
3772
3773 \section1 QToolBar
3774
3775 The old \c QToolBar class, which worked with the old \c
3776 QMainWindow and \c QDockArea classes and inherited from \c
3777 QDockWindow, has been renamed Q3ToolBar and moved to
3778 Qt3Support. Note that, when using Q3ToolBar, the toolbar's actions
3779 must be \l {Q3Action}s.
3780
3781 Use the new QToolBar class in new applications.
3782
3783 \note \l{Q3ToolBar}'s
3784 \l{Q3DockWindow::setHorizontallyStretchable()}{horizontallyStretchable}
3785 property can be achieved in QToolBar with
3786 \l{QWidget#Size Hints and Size Policies}{size policies}.
3787
3788 \section1 QToolButton
3789
3790 See \l{#properties}{Properties} for a list of QToolButton properties
3791 in Qt 3 that have changed in Qt 4.
3792
3793 Note that many of the properties that could previously be set in
3794 the constructor must now be set separately.
3795
3796 \section1 QToolTip
3797
3798 The QToolTip::setGloballyEnabled() function no longer exists.
3799 Tooltips can be disabled by \l{QObject::installEventFilter()}{installing
3800 an event filter} on qApp (the unique QApplication object) to block events
3801 of type QEvent::ToolTip.
3802
3803 \section1 QUriDrag
3804
3805 The \c QUriDrag class has been renamed Q3UriDrag and moved to the
3806 Qt3Support library. In Qt 4, use QMimeData instead
3807 and call QMimeData::setUrl() to set the URL.
3808
3809 See \l{Porting to Qt 4 - Drag and Drop} for a comparison between
3810 the drag and drop APIs in Qt 3 and Qt 4.
3811
3812 \section1 QUrl
3813
3814 The QUrl class has been rewritten from scratch in Qt 4 to be more
3815 standard-compliant. The old QUrl class has been renamed Q3Url and
3816 moved to the Qt3Support library.
3817
3818 The new QUrl class provides an extensive list of compatibility
3819 functions to ease porting from Q3Url to QUrl. A few functions
3820 require you to change your code:
3821
3822 \list
3823 \o Q3Url::Q3Url(const Q3Url &, const QString &, bool) can be
3824 simulated by combining the URLs manually (using
3825 QString::operator+(), for example).
3826 \o Q3Url::setEncodedPathAndQuery(const QString &) is replaced by
3827 QUrl::setPath() and QUrl::setEncodedQuery().
3828 \o Q3Url::encodedPathAndQuery() is replaced by QUrl::path() and
3829 QUrl::encodedQuery().
3830 \o Q3Url::isLocalFile() can be simulated by checking that
3831 QUrl::protocol() is "file".
3832 \o Q3Url::toString(bool, bool) is replaced by
3833 QUrl::toString(int), where the \c int parameter specifies a
3834 combination of \l{QUrl::FormattingOptions}{formatting
3835 options}.
3836 \endlist
3837
3838 \section1 QUrlOperator
3839
3840 The \c QUrlOperator class is no longer part of the public Qt API.
3841 It has been renamed Q3UrlOperator and moved to Qt3Support.
3842
3843 From Qt 4.4, the Network Access API provides a subset of the features
3844 provided by \c QUrlOperator that are mostly intended for use with
3845 applications that use the HTTP and FTP protocols. See the
3846 QNetworkRequest, QNetworkReply, and QNetworkAccessManager documentation
3847 for further details.
3848
3849 \target qvaluelist.section
3850 \section1 QValueList<T>
3851
3852 The QValueList<T> class has been replaced by QList<T> and
3853 QLinkedList<T> in Qt 4. As a help when porting older Qt
3854 applications, the Qt3Support library contains a
3855 QValueList<T> class implemented in terms of the new
3856 QLinkedList<T>. Similarly, it contains QValueListIterator<T> and
3857 QValueListConstIterator<T> classes implemented in terms of
3858 QLinkedList<T>::iterator and QLinkedList<T>::const_iterator.
3859
3860 When porting to Qt 4, you have the choice of using QList<T> or
3861 QLinkedList<T> as alternatives to QValueList<T>. QList<T> has an
3862 index-based API and provides very fast random access
3863 (QList::operator[]), whereas QLinkedList<T> has an iterator-based
3864 API.
3865
3866 Here's a list of problem functions:
3867
3868 \list
3869 \o QValueList(const std::list<T> &) doesn't exist in QList or
3870 QLinkedList. You can simulate it by calling
3871 \l{QLinkedList::append()}{append()} in a loop.
3872
3873 \o QValueList::insert(iterator, size_type, const T& x) doesn't
3874 exist in QList or QLinkedList. Call
3875 \l{QLinkedList::insert()}{insert()} repeatedly instead.
3876
3877 \o QValueList::fromLast() doesn't exist in QList or QLinkedList. Use
3878 QValueList::end() instead.
3879
3880 \oldcode
3881 for (QValueList<T>::iterator i = list.fromLast(); i != list.begin(); --i)
3882 do_something(*i);
3883 \newcode
3884 QLinkedList<T>::iterator i = list.end();
3885 while (i != list.begin()) {
3886 --i; // decrement i before using it
3887 do_something(*i);
3888 }
3889 \endcode
3890
3891 \o QValueList::append() and QValueList::prepend() return an
3892 iterator to the inserted item. QList's and QLinkedList's
3893 corresponding functions don't, but it's not a problem because
3894 QValueList::prepend() always returns begin() and append()
3895 always returns QValueList::end() - 1.
3896
3897 \o QValueList::at(\e i) return an iterator to the item at index
3898 \e i. This corresponds to QList::begin() + \e i.
3899
3900 \o QValueList::contains(const T &) corresponds to
3901 QList::count(const T &) and QLinkedList::count(const T &).
3902 \endlist
3903
3904 \section1 QValueVector<T>
3905
3906 The QValueVector<T> class has been replaced by QVector<T> in Qt
3907 4. As a help when porting older Qt applications, the Qt3Support
3908 library contains a Q3ValueVector<T> class implemented in terms of
3909 the new QVector<T>.
3910
3911 When porting from QValueVector<T> to QVector<T>, you might run
3912 into the following incompatibilities:
3913
3914 \list
3915 \o QValueVector(const std::vector<T> &) doesn't exist in QVector.
3916 You can simulate it by calling QVector::append()} in a loop.
3917 \o QValueVector::resize(int, const T &) doesn't exist in QVector.
3918 If you want the new items to be initialized with a particular
3919 value, use QVector::insert() instead.
3920 \o QValueVector::at() on a non-const vector returns a non-const
3921 reference. This corresponds to QVector::operator[]().
3922 \o Both QValueVector::at() functions have an \e ok parameter of
3923 type \c{bool *} that is set to true if the index is within
3924 bounds. This functionality doesn't exist in QVector; instead,
3925 check the index against QVector::size() yourself.
3926 \endlist
3927
3928 See \l{Generic Containers} for an overview of the Qt 4 container
3929 classes.
3930
3931 \section1 QVariant
3932
3933 Some changes to the rest of the Qt library have
3934 implications on QVariant:
3935
3936 \list 1
3937 \o The \c QVariant::ColorGroup enum value is defined only
3938 if \c QT3_SUPPORT is defined.
3939 \o The \c QVariant::IconSet enum value has been renamed
3940 QVariant::Icon.
3941 \o The \c QVariant::CString enum value is now a synonym for
3942 QVariant::ByteArray.
3943 \endlist
3944
3945 Also, the QVariant(bool, int) constructor has been replaced by QVariant(bool).
3946 Old code like QVariant(true, 0) should be replaced with QVariant(true); otherwise,
3947 the QVariant(int, void *) overload might accidentally be triggered.
3948
3949 Many of QVariant's convenience functions in Qt 3, such as toColor() and
3950 toKeySequence(), have been removed to enable QVariant to be part of the
3951 QtCore module. QVariant is still able to hold values of these types.
3952
3953 Types which are not supported by any of the QVariant constructors can be
3954 stored as variants with the QVariant::fromValue() function. Types with no
3955 suitable convenience function for unpacking can be retrieved with the
3956 QVariant::value() function or passed directly to classes that implement
3957 the QVariant() operator.
3958
3959 \table
3960 \header \o Qt 3 function \o Qt 4 function
3961 \input porting4-removedvariantfunctions.qdocinc
3962 \endtable
3963
3964 See the QVariant::Type enum for a list of types supported by QVariant.
3965
3966 \section1 QVBox
3967
3968 The \c QVBox class is now only available as Q3VBox in Qt 4. You
3969 can achieve the same result as \c QVBox by creating a QWidget
3970 with a vertical layout:
3971
3972 \oldcode
3973 QVBox *vbox = new QVBox;
3974 QPushButton *child1 = new QPushButton(vbox);
3975 QPushButton *child2 = new QPushButton(vbox);
3976 \newcode
3977 QWidget *vbox = new QWidget;
3978 QPushButton *child1 = new QPushButton;
3979 QPushButton *child2 = new QPushButton;
3980
3981 QVBoxLayout *layout = new QVBoxLayout;
3982 layout->addWidget(child1);
3983 layout->addWidget(child2);
3984 vbox->setLayout(layout);
3985 \endcode
3986
3987 Note that child widgets are not automatically placed into the widget's
3988 layout; you will need to manually add each widget to the QVBoxLayout.
3989
3990 \section1 QVGroupBox
3991
3992 The \c QVGroupBox class has been renamed Q3VGroupBox and moved to
3993 the Qt3Support library.
3994 Qt 4 does not provide a specific replacement class for \c QVGroupBox
3995 since QGroupBox is designed to be a generic container widget. As a
3996 result, you need to supply your own layout for any child widgets.
3997
3998 See \l{#QGroupBox} for more information about porting code that uses
3999 group boxes.
4000
4001 \section1 QWhatsThis
4002
4003 The QWhatsThis class has been redesigned in Qt 4. The old \c
4004 QWhatsThis class is available as Q3WhatsThis in Qt3Support.
4005
4006 \section1 QWidget
4007
4008 Widget background painting has been greatly improved, supporting
4009 flicker-free updates and making it possible to have
4010 semi-transparent widgets. This renders the following background
4011 handling functions obsolete:
4012
4013 \list
4014 \o QWidget::repaint(bool noErase) - the \c noErase boolean parameter is gone
4015 \o QWidget::setBackgroundMode(BackgroundMode m)
4016 \o QWidget::backgroundBrush() const
4017 \o QWidget::setBackgroundPixmap(const QPixmap &pm)
4018 \o QWidget::backgroundPixmap() const
4019 \o QWidget::setBackgroundColor(const QColor &c)
4020 \o QWidget::backgroundColor() const
4021 \o QWidget::foregroundColor() const
4022 \o QWidget::eraseColor() const
4023 \o QWidget::setEraseColor(const QColor &c)
4024 \o QWidget::erasePixmap() const
4025 \o QWidget::setErasePixmap(const QPixmap &p)
4026 \o QWidget::paletteForegroundColor()
4027 \o QWidget::setPaletteForegroundColor(const QColor &c)
4028 \o QWidget::paletteBackgroundColor()
4029 \o QWidget::setPaletteBackgroundColor(const QColor &c)
4030 \o QWidget::paletteBackgroundPixmap() const
4031 \o QWidget::setPaletteBackgroundPixmap(const QPixmap &p)
4032 \o QWidget::erase()
4033 \o QWidget::erase(const QRect &r)
4034 \o QWidget::setBackgroundOrigin( BackgroundOrigin )
4035 \o QWidget::BackgroundOrigin backgroundOrigin() const
4036 \o QWidget::backgroundOffset()
4037 \endlist
4038
4039 Sample code on how to do obtain similar behavior from Qt 4, previously
4040 handled by some of the above functions can be found in the
4041 \l{http://doc.trolltech.com/qwidget-qt3.html}{Qt 3 Support Members for QWidget}
4042 page.
4043
4044 A widget now receives change events in its QWidget::changeEvent()
4045 handler. This makes the following virtual change handlers obsolete:
4046
4047 \list
4048 \o QWidget::styleChange - use QEvent::StyleChange
4049 \o QWidget::enabledChange - use QEvent::EnabledChange
4050 \o QWidget::paletteChange - use QEvent::PaletteChange
4051 \o QWidget::fontChange - use QEvent::FontChange
4052 \o QWidget::windowActivationChange - use QEvent::ActivationChange
4053 \o QWidget::languageChange - use QEvent::LanguageChange
4054 \endlist
4055
4056 The following functions were slots, but are no more:
4057 \list
4058 \o QWidget::clearFocus()
4059 \o QWidget::setMouseTracking()
4060 \o QWidget::stackUnder(QWidget*)
4061 \o QWidget::move(int x, int y)
4062 \o QWidget::move(const QPoint &)
4063 \o QWidget::resize(int w, int h)
4064 \o QWidget::resize(const QSize &)
4065 \o QWidget::setGeometry(int x, int y, int w, int h)
4066 \o QWidget::setGeometry(const QRect &)
4067 \o QWidget::adjustSize()
4068 \o QWidget::update(int x, int y, int w, int h)
4069 \o QWidget::update(const QRect&)
4070 \o QWidget::repaint(bool erase)
4071 \o QWidget::repaint(int x, int y, int w, int h, bool erase)
4072 \o QWidget::repaint(const QRect &, bool erase)
4073 \o QWidget::repaint(const QRegion &, bool erase)
4074 \o QWidget::setCaption(const QString &)
4075 \o QWidget::setIcon(const QPixmap &)
4076 \o QWidget::setIconText(const QString &)
4077 \endlist
4078
4079 The following functions were incorrectly marked as virtual:
4080
4081 \list
4082 \o QWidget::close(bool alsoDelete)
4083 \o QWidget::create(WId, bool, bool)
4084 \o QWidget::destroy(bool)
4085 \o QWidget::move(int x, int y)
4086 \o QWidget::reparent(QWidget *parent, WFlags, const QPoint &, bool)
4087 \o QWidget::resize(int w, int h)
4088 \o QWidget::setAcceptDrops(bool on)
4089 \o QWidget::setActiveWindow()
4090 \o QWidget::setAutoMask(bool)
4091 \o QWidget::setBackgroundColor(const QColor &)
4092 \o QWidget::setBackgroundMode(BackgroundMode)
4093 \o QWidget::setBackgroundOrigin(BackgroundOrigin)
4094 \o QWidget::setBackgroundPixmap(const QPixmap &)
4095 \o QWidget::setCaption(const QString &)
4096 \o QWidget::setCursor(const QCursor &)
4097 \o QWidget::setEnabled(bool)
4098 \o QWidget::setEraseColor(const QColor &)
4099 \o QWidget::setErasePixmap(const QPixmap &)
4100 \o QWidget::setFocus()
4101 \o QWidget::setFocusPolicy(FocusPolicy)
4102 \o QWidget::setFocusProxy(QWidget *)
4103 \o QWidget::setFont(const QFont &)
4104 \o QWidget::setGeometry(const QRect &)
4105 \o QWidget::setGeometry(int x, int y, int w, int h)
4106 \o QWidget::setIcon(const QPixmap &)
4107 \o QWidget::setIconText(const QString &)
4108 \o QWidget::setKeyCompression(bool)
4109 \o QWidget::setMask(const QBitmap &)
4110 \o QWidget::setMask(const QRegion &)
4111 \o QWidget::setMaximumSize(int maxw, int maxh)
4112 \o QWidget::setMicroFocusHint(int x, int y, int w, int h, bool, QFont *f)
4113 \o QWidget::setMinimumSize(int minw, int minh)
4114 \o QWidget::setMouseTracking(bool enable)
4115 \o QWidget::setPalette(const QPalette &)
4116 \o QWidget::setPaletteBackgroundColor(const QColor &)
4117 \o QWidget::setPaletteBackgroundPixmap(const QPixmap &)
4118 \o QWidget::setSizeIncrement(int w, int h)
4119 \o QWidget::setSizePolicy(QSizePolicy)
4120 \o QWidget::setUpdatesEnabled(bool enable)
4121 \o QWidget::setWState(uint)
4122 \o QWidget::show()
4123 \o QWidget::showFullScreen()
4124 \o QWidget::showMaximized()
4125 \o QWidget::showMinimized()
4126 \o QWidget::showNormal()
4127 \o QWidget::sizePolicy()
4128 \o QWidget::unsetCursor()
4129 \endlist
4130
4131 The internal clearWState() function was removed. Use
4132 QWidget::setAttribute() instead.
4133
4134 setWFlags() was renamed QWidget::setWindowFlags().
4135
4136 clearWFlags() has no direct replacement. You can use
4137 QWidget::setAttribute() instead. For example,
4138 \c{setAttribute(..., false)} to clear an attribute. More information
4139 is available \l{http://doc.trolltech.com/qwidget.html#setAttribute}{here}.
4140
4141 testWFlags() was renamed to \l{QWidget::testAttribute()}{testAttribute()}.
4142
4143 See \l{#properties}{Properties} for a list of QWidget properties
4144 in Qt 3 that have changed in Qt 4.
4145
4146 \section1 QWidgetFactory
4147
4148 The \c QWidgetFactory class has been replaced by QFormBuilder in Qt 4.
4149
4150 \section1 QWidgetIntDict
4151
4152 The QWidgetIntDict class was a synonym for QIntDict<QWidget>. It
4153 is no longer available in Qt 4. If you link against Qt3Support,
4154 you can use Q3IntDict<QWidget> instead; otherwise, see the
4155 \l{#qdict.section}{section on QDict<T>}.
4156
4157 \target qwidgetlist.section
4158 \section1 QWidgetList
4159
4160 In Qt 3, the QWidgetList class was a typedef for
4161 QPtrList<QWidget>. In Qt 4, it is a typedef for QList<QWidget *>.
4162 See the \l{#qptrlist.section}{section on QPtrList<T>}.
4163
4164 \section1 QWidgetPlugin
4165
4166 The QWidgetPlugin class is no longer available in Qt 4. To create
4167 custom widget plugins, subclass QDesignerCustomWidgetInterface to
4168 provide information about the custom widget, and build a plugin in
4169 the way described in the \l{designer/customwidgetplugin}{Custom
4170 Widget Plugin} example.
4171
4172 \section1 QWidgetStack
4173
4174 The QWidgetStack class is no longer part of the Qt public API. It
4175 has been renamed Q3WidgetStack and moved to Qt3Support. In Qt 4
4176 applications, you can use QStackedWidget instead to obtain the
4177 same results.
4178
4179 \section1 QWizard
4180
4181 The \c QWizard class was reintroduced in Qt 4.3. See the
4182 \l{Trivial Wizard Example}, \l{License Wizard Example} and
4183 \l{Class Wizard Example} for more details.
4184
4185 \section1 QWorkspace
4186
4187 The \c QWorkspace in Qt 4 class requires explicit adding of MDI
4188 windows with QWorkspace::addWindow().
4189*/
4190
4191/*!
4192 \page porting4-virtual-functions.html
4193 \title Porting to Qt 4 - Virtual Functions
4194 \contentspage {Porting Guides}{Contents}
4195 \previouspage Porting to Qt 4
4196 \nextpage Porting to Qt 4 - Drag and Drop
4197 \ingroup porting
4198 \brief An overview of changes to virtual functions in Qt 4.
4199
4200 \section1 Virtual Functions
4201
4202 Virtual functions that changed their signature in Qt 4:
4203
4204 \table
4205 \header \o Qt 3 function signature \o Qt 4 function signature
4206 \input porting4-modifiedvirtual.qdocinc
4207 \endtable
4208
4209 Virtual functions that are not virtual in Qt 4:
4210
4211 \table
4212 \header \o Qt 3 function \o Comment
4213 \input porting4-removedvirtual.qdocinc
4214 \endtable
4215*/
Note: See TracBrowser for help on using the repository browser.