Porting to Qt 4
This document describes the process of porting applications from Qt 3 to Qt 4. If you haven't yet made the decision about porting, or are unsure about whether it is worth it, take a look at the key features offered by Qt 4. See alsoMoving from Qt 3 to Qt 4 for tips on how to write Qt 3 code that is easy to port to Qt 4.
Other porting guides:
The Qt 4 series is not binary compatible with the 3 series. This means programs compiled for Qt 3 must be recompiled to work with Qt 4. Qt 4 is also not completely sourcecompatible with 3, however nearly all points of incompatibility cause compiler errors or run-time messages (rather than mysterious results). Qt 4 includes many additional features and discards obsolete functionality. Porting from Qt 3 to Qt 4 requires some effort, but once completed the considerable additional power and flexibility of Qt 4 is available for use in your applications.
To port code from Qt 3 to Qt 4:
The qt3to4 porting tool replaces occurrences of Qt 3 classes that don't exist anymore in Qt 4 with the corresponding Qt 3 support class; for example, QListBox is turned into Q3ListBox.
At some point, you might want to stop linking against the Qt 3 support library (Qt3Support) and take advantage of Qt 4's new features. The instructions below explain how to do that for each compatibility class.
In addition to the Qt3Support classes (such as Q3Action,Q3ListBox, and Q3ValueList), Qt 4 provides compatibility functions when it's possible for an old API to cohabit with the new one. For example, QString provides aQString::simplifyWhiteSpace() compatibility function that's implemented inline and that simply callsQString::simplified(). The compatibility functions are not documented here; instead, they are documented for each class.
If you have the line QT += qt3support in your .pro file,qmake will automatically define the QT3_SUPPORT symbol, turning on compatibility function support. You can also define the symbol manually (e.g., if you don't want to link against the Qt3Support library), or you can defineQT3_SUPPORT_WARNINGS instead, telling the compiler to emit a warning when a compatibility function is called. (This works only with GCC 3.2+ and MSVC 7.)
If you get stuck, ask on the qt-interest mailing list. If you are a licensed customer, you can also contact Qt's technical support team.
Table of contents:
In Qt 3, it was possible to use the qt_cast() function to determine whether instances of QObject subclasses could be safely cast to derived types of those subclasses. For example, if a QFrame instance is passed to a function whose signature specifies a QWidget pointer as its argument, qt_cast() could be used to obtain a QFramepointer so that the instance's functions can be accessed.
In Qt 4, much of this functionality is provided by theqobject_cast() function, and additional functions also provide similar functionality for certain non-QObject types:
Qt 3 function | Qt 4 function |
---|---|
T *qt_cast<T *>(QObject *) |
T *qobject_cast<T *>(QObject *) |
|
T qgraphicsitem_cast<T>(QGraphicsItem*) |
|
T qstyleoption_cast<T>(QStyleOption*) |
|
T qvariant_cast<T>(const QVariant &) |
|
T qdbus_cast(const QDBusArgument &) |
The table below lists the classes that have been renamed in Qt 4. If you compile your applications with QT3_SUPPORTdefined, the old names will be available.
Whenever you see an occurrence of the name on the left, you can safely replace it with the Qt 4 equivalent in your program. The qt3to4 tool performs the conversion automatically.
Qt 3 class name | Qt 4 class name |
---|---|
QIconSet |
QIcon |
QWMatrix |
QMatrix |
QGuardedPtr |
QPointer |
The table below lists the enums and typedefs that have been renamed in Qt 4. If you compile your applications withQT3_SUPPORT defined, the old names will be available.
Whenever you see an occurrence of the name on the left, you can safely replace it with the Qt 4 equivalent in your program. The qt3to4 tool performs the conversion automatically.
Qt 3 type name | Qt 4 type name |
---|---|
QApplication::ColorMode |
QApplication::ColorSpec |
QButton::ToggleState |
QCheckBox::ToggleState |
QCursorShape |
Qt::CursorShape |
QFile::FilterSpec |
QFile::Filters |
QFile::PermissionSpec |
QFile::Permission |
QFile::SortSpec |
QFile::SortFlags |
QFile::Status |
QFile::Error |
QFileInfo::PermissionSpec |
QFile::Permission |
QGrid::Direction |
Qt::Orientation |
QGridWidget::Direction |
Qt::Orientation |
QIODevice::Offset |
qlonglong |
QImage::ScaleMode |
Qt::AspectRatioMode |
QSize::ScaleMode |
Qt::AspectRatioMode |
QSocket::Error |
Q3Socket::Error |
QSocket::State |
Q3Socket::State |
QStyle::SCFlags |
QStyle::SubControls |
QStyle::SFlags |
QStyle::State |
QTS |
QTextStream |
QUrlDrag |
QUriDrag |
QWidget::FocusPolicy |
Qt::FocusPolicy |
Q_LLONG |
qlonglong |
Q_ULLONG |
qulonglong |
Qt::Dock |
Qt::ToolBarDock |
Qt::MacintoshVersion |
QSysInfo::MacVersion |
Qt::TextFlags |
Qt::TextFlag |
Qt::WindowsVersion |
QSysInfo::WinVersion |
The table below lists the enum values that have been renamed in Qt 4. If you compile your applications withQT3_SUPPORT defined, the old names will be available.
Whenever you see an occurrence of the name on the left, you can safely replace it with the Qt 4 equivalent in your program. The qt3to4 tool performs the conversion automatically.
Qt 3 enum value name | Qt 4 enum value name |
---|---|
IO_Append |
QIODevice::Append |
IO_ReadOnly |
QIODevice::ReadOnly |
IO_ReadWrite |
QIODevice::ReadWrite |
IO_Translate |
QIODevice::Text |
IO_Truncate |
QIODevice::Truncate |
IO_WriteOnly |
QIODevice::WriteOnly |
IO_Raw |
QIODevice::Unbuffered |
QAccessible::Moveable |
QAccessible::Movable |
QApplication::CustomColors |
QApplication::CustomColor |
QApplication::NormalColors |
QApplication::NormalColor |
QButton::NoChange |
QCheckBox::NoChange |
QButton::Off |
QCheckBox::Off |
QButton::On |
QCheckBox::On |
QChar::Single |
QChar::NoDecomposition |
QChar::byteOrderMark |
QChar::ByteOrderMark |
QChar::byteOrderSwapped |
QChar::ByteOrderSwapped |
QChar::nbsp |
QChar::Nbsp |
QChar::null |
QChar::Null |
QChar::replacement |
QChar::ReplacementCharacter |
QComboBox::AfterCurrent |
QComboBox::InsertAfterCurrent |
QComboBox::AtBottom |
QComboBox::InsertAtBottom |
QComboBox::AtCurrent |
QComboBox::InsertAtCurrent |
QComboBox::AtTop |
QComboBox::InsertAtTop |
QComboBox::BeforeCurrent |
QComboBox::InsertBeforeCurrent |
QComboBox::NoInsertion |
QComboBox::NoInsert |
QDir::DefaultFilter |
QDir::NoFilter |
QDir::DefaultSort |
QDir::NoSort |
QEvent::Accel |
QEvent::Shortcut |
QEvent::AccelOverride |
QEvent::ShortcutOverride |
QEvent::CaptionChange |
QEvent::WindowTitleChange |
QEvent::ChildInserted |
QEvent::ChildAdded |
QEvent::IMCompose |
QEvent::InputMethodCompose |
QEvent::IMEnd |
QEvent::InputMethodEnd |
QEvent::IMStart |
QEvent::InputMethodStart |
QEvent::IconChange |
QEvent::WindowIconChange |
QEvent::LayoutHint |
QEvent::LayoutRequest |
QEvent::Reparent |
QEvent::ParentChange |
QFileInfo::ExeGroup |
QFile::ExeGroup |
QFileInfo::ExeOther |
QFile::ExeOther |
QFileInfo::ExeOwner |
QFile::ExeOwner |
QFileInfo::ExeUser |
QFile::ExeUser |
QFileInfo::ReadGroup |
QFile::ReadGroup |
QFileInfo::ReadOther |
QFile::ReadOther |
QFileInfo::ReadOwner |
QFile::ReadOwner |
QFileInfo::ReadUser |
QFile::ReadUser |
QFileInfo::WriteGroup |
QFile::WriteGroup |
QFileInfo::WriteOther |
QFile::WriteOther |
QFileInfo::WriteOwner |
QFile::WriteOwner |
QFileInfo::WriteUser |
QFile::WriteUser |
QFrame::GroupBoxPanel |
QFrame::StyledPanel |
QFrame::LineEditPanel |
QFrame::StyledPanel |
QFrame::MenuBarPanel |
QFrame::StyledPanel |
QFrame::PopupPanel |
QFrame::StyledPanel |
QFrame::TabWidgetPanel |
QFrame::StyledPanel |
QFrame::ToolBarPanel |
QFrame::StyledPanel |
QImage::ScaleFree |
Qt::IgnoreAspectRatio |
QImage::ScaleMax |
Qt::KeepAspectRatioByExpanding |
QImage::ScaleMin |
Qt::KeepAspectRatio |
Qt::Identical |
QKeySequence::ExactMatch |
Qt::NoMatch |
QKeySequence::NoMatch |
Qt::PartialMatch |
QKeySequence::PartialMatch |
QLayout::Auto |
QLayout::SetDefaultConstraint |
QLayout::Fixed |
QLayout::SetFixedSize |
QLayout::FreeResize |
QLayout::SetNoConstraint |
QLayout::Minimum |
QLayout::SetMinimumSize |
QMacStyle::SizeNone |
QMacStyle::SizeDefault |
QSettings::Global |
QSettings::SystemScope |
QSettings::User |
QSettings::UserScope |
QSize::ScaleFree |
Qt::IgnoreAspectRatio |
QSize::ScaleMax |
Qt::KeepAspectRatioByExpanding |
QSize::ScaleMin |
Qt::KeepAspectRatio |
QSizePolicy::Horizontal |
QSizePolicy::Horizontally |
QSizePolicy::Vertical |
QSizePolicy::Vertically |
QSlider::Above |
QSlider::TicksAbove |
QSlider::Below |
QSlider::TicksBelow |
QSlider::Both |
QSlider::TicksBothSides |
QSlider::Left |
QSlider::TicksLeft |
QSlider::NoMarks |
QSlider::NoTicks |
QSlider::Right |
QSlider::TicksRight |
QSocket::Closing |
Q3Socket::Closing |
QSocket::Connected |
Q3Socket::Connected |
QSocket::Connecting |
Q3Socket::Connecting |
QSocket::Connection |
Q3Socket::Connection |
QSocket::ErrConnectionRefused |
Q3Socket::ErrConnectionRefused |
QSocket::ErrHostNotFound |
Q3Socket::ErrHostNotFound |
QSocket::ErrSocketRead |
Q3Socket::ErrSocketRead |
QSocket::HostLookup |
QAbstractSocket::HostLookupState |
QSocket::Idle |
QAbstractSocket::UnconnectedState |
QSqlError::Connection |
QSqlError::ConnectionError |
QSqlError::None |
QSqlError::NoError |
QSqlError::Statement |
QSqlError::StatementError |
QSqlError::Transaction |
QSqlError::TransactionError |
QSqlError::Unknown |
QSqlError::UnknownError |
QStyle::CC_ListView |
QStyle::CC_Q3ListView |
QStyle::SH_UnderlineAccelerator |
QStyle::SH_UnderlineShortcut |
QStyle::Style_Active |
QStyle::State_Active |
QStyle::Style_AutoRaise |
QStyle::State_AutoRaise |
QStyle::Style_Bottom |
QStyle::State_Bottom |
QStyle::Style_Children |
QStyle::State_Children |
QStyle::Style_Default |
QStyle::State_None |
QStyle::Style_Down |
QStyle::State_DownArrow |
QStyle::Style_Editing |
QStyle::State_Editing |
QStyle::Style_Enabled |
QStyle::State_Enabled |
QStyle::Style_FocusAtBorder |
QStyle::State_FocusAtBorder |
QStyle::Style_HasFocus |
QStyle::State_HasFocus |
QStyle::Style_Horizontal |
QStyle::State_Horizontal |
QStyle::Style_Item |
QStyle::State_Item |
QStyle::Style_MouseOver |
QStyle::State_MouseOver |
QStyle::Style_NoChange |
QStyle::State_NoChange |
QStyle::Style_None |
QStyle::State_None |
QStyle::Style_Off |
QStyle::State_Off |
QStyle::Style_On |
QStyle::State_On |
QStyle::Style_Open |
QStyle::State_Open |
QStyle::Style_Raised |
QStyle::State_Raised |
QStyle::Style_Rectangle |
QStyle::State_Rectangle |
QStyle::Style_Selected |
QStyle::State_Selected |
QStyle::Style_Sibling |
QStyle::State_Sibling |
QStyle::Style_Sunken |
QStyle::State_Sunken |
QStyle::Style_Top |
QStyle::State_Top |
QStyle::Style_Up |
QStyle::State_Up |
QTabBar::RoundedAbove |
QTabBar::RoundedNorth |
QTabBar::RoundedBelow |
QTabBar:: RoundedSouth |
QTabBar::TriangularAbove |
QTabBar:: TriangularNorth |
QTabBar::TriangularBelow |
QTabBar:: TriangularSouth |
QTextEdit::MovePgDown |
QTextEdit::MovePageDown |
QTextEdit::MovePgUp |
QTextEdit::MovePageUp |
QToolButton::Right |
QToolButton::BesideIcon |
QToolButton::Under |
QToolButton::BelowIcon |
QValidator::Valid |
QValidator::Intermediate |
QVariant::IconSet |
QCoreVariant::Icon |
QWidget::ClickFocus |
Qt::ClickFocus |
QWidget::NoFocus |
Qt::NoFocus |
QWidget::StrongFocus |
Qt::StrongFocus |
QWidget::TabFocus |
Qt::TabFocus |
QWidget::WheelFocus |
Qt::WheelFocus |
Qt::AlignAuto |
Qt::AlignLeft |
Qt::AltButton |
Qt::AltModifier |
Qt::Ascending |
Qt::AscendingOrder |
Qt::Bottom |
Qt::DockBottom |
Qt::BottomLeft |
Qt::BottomLeftCorner |
Qt::BottomRight |
Qt::BottomRightCorner |
Qt::BreakAnywhere |
Qt::TextWrapAnywhere |
Qt::ControlButton |
Qt::ControlModifier |
Qt::CustomPattern |
Qt::TexturePattern |
Qt::Descending |
Qt::DescendingOrder |
Qt::DontClip |
Qt::TextDontClip |
Qt::DontPrint |
Qt::TextDontPrint |
Qt::ExpandTabs |
Qt::TextExpandTabs |
Qt::IncludeTrailingSpaces |
Qt::TextIncludeTrailingSpaces |
Qt::KeyButtonMask |
Qt::KeyboardModifierMask |
Qt::Key_BackSpace |
Qt::Key_Backspace |
Qt::Key_BackTab |
Qt::Key_Backtab |
Qt::Key_MediaPrev |
Qt::Key_MediaPrevious |
Qt::Key_Next |
Qt::Key_PageDown |
Qt::Key_Prior |
Qt::Key_PageUp |
Qt::Key_aacute |
Qt::Key_Aacute |
Qt::Key_acircumflex |
Qt::Key_Acircumflex |
Qt::Key_adiaeresis |
Qt::Key_Adiaeresis |
Qt::Key_ae |
Qt::Key_AE |
Qt::Key_agrave |
Qt::Key_Agrave |
Qt::Key_aring |
Qt::Key_Aring |
Qt::Key_atilde |
Qt::Key_Atilde |
Qt::Key_ccedilla |
Qt::Key_Ccedilla |
Qt::Key_eacute |
Qt::Key_Eacute |
Qt::Key_ecircumflex |
Qt::Key_Ecircumflex |
Qt::Key_ediaeresis |
Qt::Key_Ediaeresis |
Qt::Key_egrave |
Qt::Key_Egrave |
Qt::Key_eth |
Qt::Key_ETH |
Qt::Key_iacute |
Qt::Key_Iacute |
Qt::Key_icircumflex |
Qt::Key_Icircumflex |
Qt::Key_idiaeresis |
Qt::Key_Idiaeresis |
Qt::Key_igrave |
Qt::Key_Igrave |
Qt::Key_ntilde |
Qt::Key_Ntilde |
Qt::Key_oacute |
Qt::Key_Oacute |
Qt::Key_ocircumflex |
Qt::Key_Ocircumflex |
Qt::Key_odiaeresis |
Qt::Key_Odiaeresis |
Qt::Key_ograve |
Qt::Key_Ograve |
Qt::Key_oslash |
Qt::Key_Ooblique |
Qt::Key_otilde |
Qt::Key_Otilde |
Qt::Key_thorn |
Qt::Key_THORN |
Qt::Key_uacute |
Qt::Key_Uacute |
Qt::Key_ucircumflex |
Qt::Key_Ucircumflex |
Qt::Key_udiaeresis |
Qt::Key_Udiaeresis |
Qt::Key_ugrave |
Qt::Key_Ugrave |
Qt::Key_yacute |
Qt::Key_Yacute |
Qt::Keypad |
Qt::KeypadModifier |
Qt::Left |
Qt::DockLeft |
Qt::MV_10_DOT_0 |
QSysInfo::MV_10_0 |
Qt::MV_10_DOT_1 |
QSysInfo::MV_10_1 |
Qt::MV_10_DOT_2 |
QSysInfo::MV_10_2 |
Qt::MV_10_DOT_3 |
QSysInfo::MV_10_3 |
Qt::MV_10_DOT_4 |
QSysInfo::MV_10_4 |
Qt::MV_9 |
QSysInfo::MV_9 |
Qt::MV_CHEETAH |
QSysInfo::MV_10_0 |
Qt::MV_JAGUAR |
QSysInfo::MV_10_2 |
Qt::MV_PANTHER |
QSysInfo::MV_10_3 |
Qt::MV_PUMA |
QSysInfo::MV_10_1 |
Qt::MV_TIGER |
QSysInfo::MV_10_4 |
Qt::MV_Unknown |
QSysInfo::MV_Unknown |
Qt::MetaButton |
Qt::MetaModifier |
Qt::Minimized |
Qt::DockMinimized |
Qt::NoAccel |
Qt::TextHideMnemonic |
Qt::Overline |
Qt::TextOverline |
Qt::Right |
Qt::DockRight |
Qt::ShiftButton |
Qt::ShiftModifier |
Qt::ShowPrefix |
Qt::TextShowMnemonic |
Qt::SingleLine |
Qt::TextSingleLine |
Qt::StrikeOut |
Qt::TextStrikeOut |
Qt::Top |
Qt::DockTop |
Qt::TopLeft |
Qt::TopLeftCorner |
Qt::TopRight |
Qt::TopRightCorner |
Qt::TornOff |
Qt::DockTornOff |
Qt::Underline |
Qt::TextUnderline |
Qt::Unmanaged |
Qt::DockUnmanaged |
Qt::WNorthWestGravity |
Qt::WStaticContents |
Qt::WRepaintNoErase |
Qt::WNoAutoErase |
Qt::WStyle_Dialog |
Qt::WType_Dialog |
Qt::WStyle_NoBorderEx |
Qt::WStyle_NoBorder |
Qt::WType_Modal |
(Qt::WType_Dialog | Qt::WShowModal) |
Qt::WV_2000 |
QSysInfo::WV_2000 |
Qt::WV_2003 |
QSysInfo::WV_2003 |
Qt::WV_32s |
QSysInfo::WV_32s |
Qt::WV_95 |
QSysInfo::WV_95 |
Qt::WV_98 |
QSysInfo::WV_98 |
Qt::WV_CE |
QSysInfo::WV_CE |
Qt::WV_CENET |
QSysInfo::WV_CENET |
Qt::WV_CE_based |
QSysInfo::WV_CE_based |
Qt::WV_DOS_based |
QSysInfo::WV_DOS_based |
Qt::WV_Me |
QSysInfo::WV_Me |
Qt::WV_NT |
QSysInfo::WV_NT |
Qt::WV_NT_based |
QSysInfo::WV_NT_based |
Qt::WV_XP |
QSysInfo::WV_XP |
Qt::WordBreak |
Qt::TextWordWrap |
Qt::IbeamCursor |
Qt::IBeamCursor |
In addition, the following window flags have been either replaced with widget attributes or have been deprecated:
Qt 3 type | Qt 4 equivalent |
---|---|
Qt::WDestructiveClose |
Use QWidget::setAttribute(Qt::WA_DeleteOnClose) instead. |
Qt::WStaticContents |
Use QWidget::setAttribute(Qt::WA_StaticContents) instead. |
Qt::WNorthWestGravity |
|
Qt::WNoAutoErase |
Use QWidget::setAttribute(Qt::WA_NoBackground) instead. |
Qt::WResizeNoErase |
|
Qt::WRepaintNoErase |
|
Qt::WPaintClever |
Unnecessary in Qt 4. |
Qt::WMacNoSheet |
Unnecessary in Qt 4. |
In Qt 4.1, the widget flags used to determine window modality were replaced by a single enum that can be used to specify the modal behavior of top-level widgets:
Qt 3 type | Qt 4 equivalent |
---|---|
Qt::WShowModal |
Use QWidget::setWindowModality(Qt::ApplicationModal) instead. |
Qt::WGroupLeader |
Use QWidget::setWindowModality(Qt::WindowModal) for each child dialog of the group leader, but do not change the modality of the group leader itself. |
Some properties have been renamed in Qt 4, to make Qt's API more consistent and more intuitive. For example, QWidget's caption property has been renamed windowTitle to make it clear that it refers to the title shown in the window's title bar.
In addition, the property system has been extended to allow properties to be redefined in subclasses with the Q_PROPERTY() macro, removing the need for a Q_OVERRIDE() macro.
The table below lists the Qt properties that have been renamed in Qt 4. Occurrences of these in Qt Designer UI files are automatically converted to the new name by uic.
Qt 3 name | Qt 4 name |
---|---|
QButton::accel |
QButton::shortcut |
QButton::on |
QButton::checked |
QButton::toggleButton |
QAbstractButton::checkable |
QDial::lineStep |
QDial::singleStep |
QDial::maxValue |
QDial::maximum |
QDial::minValue |
QDial::minimum |
QDialog::modal |
QDialog::isModal |
QLineEdit::edited |
QLineEdit::modified |
QLineEdit::hasMarkedText |
QLineEdit::hasSelectedText |
QLineEdit::markedText |
QLineEdit::selectedText |
QObject::name |
QObject::objectName |
QProgressDialog::progress |
QProgressDialog::value |
QProgressDialog::totalSteps |
QProgressDialog::maximum |
QProgressDialog::wasCancelled |
QProgressDialog::wasCanceled |
QPushButton::iconSet |
QPushButton::icon |
QScrollBar::draggingSlider |
QScrollBar::sliderDown |
QScrollBar::lineStep |
QScrollBar::singleStep |
QScrollBar::maxValue |
QScrollBar::maximum |
QScrollBar::minValue |
QScrollBar::minimum |
QSlider::lineStep |
QSlider::singleStep |
QSlider::maxValue |
QSlider::maximum |
QSlider::minValue |
QSlider::minimum |
QSpinBox::lineStep |
QSpinBox::singleStep |
QSpinBox::maxValue |
QSpinBox::maximum |
QSpinBox::minValue |
QSpinBox::minimum |
QTabBar::currentTab |
QTabBar::currentIndex |
QTabWidget::currentPage |
QTabWidget::currentWidget |
QToolButton::iconSet |
QToolButton::icon |
QToolButton::textLabel |
QToolButton::text |
QWidget::caption |
QWidget::windowTitle |
QWidget::icon |
QWidget::windowIcon |
QWidget::iconText |
QWidget::windowIconText |
A handful of properties in Qt 3 are no longer properties in Qt 4, but the access functions still exist as part of the Qt 4 API. These are not used by Qt Designer; the only case where you need to worry about them is in highly dynamic applications that use Qt's meta-object system to access properties. Here's the list of these properties with the read and write functions that you can use instead:
Qt 3 property | Qt 4 read function | Qt 4 write function |
---|---|---|
QSqlDatabase::connectOptions |
QSqlDatabase::connectOptions() |
QSqlDatabase::setConnectOptions() |
QSqlDatabase::databaseName |
QSqlDatabase::databaseName() |
QSqlDatabase::setDatabaseName() |
QSqlDatabase::hostName |
QSqlDatabase::hostName() |
QSqlDatabase::setHostName() |
QSqlDatabase::password |
QSqlDatabase::password() |
QSqlDatabase::setPassword() |
QSqlDatabase::port |
QSqlDatabase::port() |
QSqlDatabase::setPort() |
QSqlDatabase::userName |
QSqlDatabase::userName() |
QSqlDatabase::setUserName() |
Some properties have been removed from Qt 4, but the associated access functions are provided ifQT3_SUPPORT is defined to help porting to Qt 4. When converting Qt 3 UI files to Qt 4, uic generates calls to the Qt 3 compatibility functions. Note that this only applies to the properties of theQt3Support library, i.e. QT3_SUPPORT properties of the other libraries must be ported manually when converting Qt 3 UI files to Qt 4.
The table below lists these properties with the read and write functions that you can use instead. The documentation for the individual functions explains how to replace them with non-compatibility Qt 4 functions.
Qt 3 property | Qt 4 read function (QT3_SUPPORT) | Qt 4 write function (QT3_SUPPORT) |
---|---|---|
QMenuBar::separator |
QMenuBar::separator() |
QMenuBar::setSeparator() |
QPushButton::menuButton |
QPushButton::isMenuButton() |
N/A |
QTabWidget::margin |
QTabWidget::margin() |
QTabWidget::setMargin() |
QTextEdit::textFormat |
QTextEdit::textFormat() |
QTextEdit::setTextFormat() |
QWidget::backgroundBrush |
QWidget::backgroundBrush() |
N/A |
QWidget::backgroundMode |
QWidget::backgroundMode() |
QWidget::setBackgroundMode() |
QWidget::backgroundOrigin |
QWidget::backgroundOrigin() |
QWidget::setBackgroundOrigin() |
QWidget::colorGroup |
QWidget::colorGroup() |
QWidget::setColorGroup() |
QWidget::customWhatsThis |
QWidget::customWhatsThis() |
QWidget::setCustomWhatsThis() |
QWidget::inputMethodEnabled |
QWidget::inputMethodEnabled() |
QWidget::setInputMethodEnabled() |
QWidget::ownCursor |
QWidget::ownCursor() |
N/A |
QWidget::ownFont |
QWidget::ownFont() |
N/A |
QWidget::ownPalette |
QWidget::ownPalette() |
N/A |
QWidget::paletteBackgroundColor |
QWidget::paletteBackgroundColor() |
QWidget::setPaletteBackgroundColor() |
QWidget::paletteBackgroundPixmap |
QWidget::paletteBackgroundPixmap() |
QWidget::setPaletteBackgroundPixmap() |
QWidget::paletteForegroundColor |
QWidget::paletteForegroundColor() |
QWidget::setPaletteForegroundColor() |
QWidget::underMouse |
QWidget::underMouse() |
N/A |
The following Qt 3 properties and their access functions are no longer available in Qt 4. In most cases, Qt 4 provides similar functionality.
Qt 3 property | Qt 4 equivalent |
---|---|
QButton::autoRepeat |
N/A |
QButton::autoResize |
Call QWidget:setFixedSize(QWidget::sizeHint()) whenever you change the contents. |
QButton::exclusiveToggle |
See QAbstractButton::autoExclusive. |
QButton::pixmap |
Use QAbstractButton::icon instead. |
QButton::toggleState |
Use QCheckBox::setState() and QCheckBox::state() instead. |
QButton::toggleType |
Use QCheckBox::setTristate() instead. |
QComboBox::autoResize |
Call QWidget:setFixedSize(QWidget::sizeHint()) whenever you change the contents. |
QFrame::contentsRect |
Use Q3Frame::contentsRect() instead. |
QFrame::margin |
Use QWidget::setContentsMargins() instead. |
QTabBar::keyboardFocusTab |
N/A |
QToolButton::offIconSet |
Use the off component of QAbstractButton::icon instead. |
QToolButton::onIconSet |
Use the on component of QAbstractButton::icon instead. |
QWidget::microFocusHint |
N/A |
QMimeSource::serialNumber () |
N/A |
Qt 4 is the first version of Qt that contains no explicitly shared classes. All classes that were explicitly shared in Qt 3 are implicitly shared in Qt 4:
This means that if you took a copy of an instance of the class (using operator=() or the class's copy constructor), any modification to the copy would affect the original and vice versa. Needless to say, this behavior is rarely desirable.
Fortunately, nearly all Qt 3 applications don't rely on explicit sharing. When porting, you typically only need to remove calls to detach() and/or copy(), which aren't necessary anymore.
If you deliberately rely on explicit sharing in your application, you can use pointers or references to achieve the same result in Qt 4.
For example, if you have code like
you can rewrite it as
(Notice the & in the parameter declaration.)
When implementing custom widgets in Qt 3, it was possible to use QPainter to draw on a widget outside paint events. This made it possible to integrate Qt applications with third party libraries and tools that impose their own rendering models. For example, a widget might be repainted in a slot using data obtained from an external source.
In Qt 4, it is only possible to paint on a widget from within its paintEvent() handler function. This restriction simplifies Qt's interaction with native window systems, improves the performance of applications by reducing the number of redraw operations, and also enables features to be implemented to improve the appearance of widgets, such as a backing store.
Generally, we recommend redesigning applications to perform all painting operations in paintEvent()functions, deferring actual painting until the next time this function is called. Applications can post paint events to trigger repaints, and it may be possible to examine your widget's internal state to determine which part of the widget needs to be repainted.
If asynchronous repaints are used extensively by your application, and it is not practical to redesign the rendering model to perform all painting operations from within a widget's paintEvent()function, it may be necessary to consider using an intermediate painting step. In this approach, one or more images can be updated asynchronously and painted on the widget in the paint event. To avoid excessive buffering, it may be worthwhile disabling the backing store by setting the widget's Qt::WA_PaintOnScreen widget attribute.
On certain platforms, the Qt::WA_PaintOutsidePaintEvent widget attribute can be set to allow a widget to be painted from outside paint events.
Note: Setting widget attributes to disable key features of Qt's widget rendering model may also cause other features to be disabled.
When QT3_SUPPORT is defined, the default connection type for signals and slots is theQt::AutoCompatConnection type. This allows so-called compatibility signals and slots (defined in Qt 3 support mode to provide Qt 3 compatibility features) to be connected to other signals and slots.
However, if Qt is compiled with debugging output enabled, and the developer uses other connection types to connect to compatibility signals and slots (perhaps by building their application without Qt 3 support enabled), then Qt will output warnings to the console to indicate that compatibility connections are being made. This is intended to be used as an aid in the process of porting a Qt 3 application to Qt 4.
The QAccel class has been renamed Q3Accel and moved to the Qt3Support module. In new applications, you have three options:
The Q3Accel class also supports multiple accelerators using the same object, by callingQ3Accel::insertItem() multiple times. In Qt 4, the solution is to create multiple QShortcut objects.
The QAccessibleInterface class has undergone some API changes in Qt 4, to make it more consistent with the rest of the Qt API.
If you have classes that inherit QAccessibleInterface or one of its subclasses (QAccessibleObject,QAccessibleWidget, etc.), you must port them the new QAccessibleInterface API.
See Virtual Functions for a list of QAccessibleInterface virtual member functions in Qt 3 that are no longer virtual in Qt 4.
The QAccessibleTitleBar has been renamed Q3AccessibleTitleBar and moved to the Qt3Supportlibrary.
The QAction class has been redesigned in Qt 4 to integrate better with the rest of the menu system. It unifies the old QMenuItem class and the old QAction class into one class, avoiding unnecessary data duplication and the need to learn two different APIs.
The old QAction and QActionGroup classes have been renamed Q3Action and Q3ActionGroup and moved to Qt3Support. In addition, the new QAction class has compatibility functions to ease transition to Qt 4. Note that when using Q3ToolBar and Q3PopupMenu, their actions must beQ3Actions.
See Virtual Functions for a list of QAction virtual member functions in Qt 3 that are no longer virtual in Qt 4.
The QAction class has been completely redesigned in Qt 4 to integrate better with the rest of the menu system. See the section on QAction for details.
The QApplication class has been split into two classes: QCoreApplication and QApplication. The new QApplication class inherits QCoreApplication and adds GUI-related functionality. In practice, this has no consequences for existing Qt applications.
In addition, the following API changes were made:
Also, QWidgetList has changed from being a typedef for QPtrList<QWidget> to being a typedef for QList<QWidget *>. See the section on QWidgetList below for details.
For example, if you have code like
you can rewrite it as
The QAquaStyle class first appeared in Qt 3.0, when the Qt for Mac OS X port was first released. It emulated Apple's "Aqua" theme. In Qt 3.1, QAquaStyle was obsoleted by QMacStyle, which uses Appearance Manager to perform its drawing.
The QAquaStyle class is no longer provided in Qt 4. Use QMacStyle instead.
QAsciiCache<T> has been renamed Q3AsciiCache<T> and moved to the Qt3Support library. It has been replaced by QCache<QByteArray, T>.
For details, read the section on QCache<T>, mentally substituting QByteArray for QString.
QAsciiDict<T> and QAsciiDictIterator<T> have been renamed Q3AsciiDict<T> andQ3AsciiDictIterator<T> and moved to the Qt3Support library. They have been replaced by the more modern QHash<Key, T> and QMultiHash<Key, T> classes and their associated iterator classes.
When porting old code that uses Q3AsciiDict<T> to Qt 4, there are four classes that you can use:
For details, read the section on QDict<T>, mentally substituting QByteArray for QString.
The QAsyncIO class was used internally in Qt 2.x in conjunction with QImageConsumer. It was obsoleted in Qt 3.0.
If you use this mechanism in your application, please submit a report to the Task Tracker on the Qt website and we will try to find a satisfactory substitute.
The undocumented QBackInsertIterator class has been removed from the Qt library. If you need it in your application, feel free to copy the source code from the Qt 3 <qtl.h> header file.
In Qt 3, QBitArray inherited from QByteArray. In Qt 4, QBitArray is a totally independent class. This makes very little difference to the user, except that the new QBitArray doesn't provide any ofQByteArray's byte-based API anymore. These calls will result in a compile-time error, except calls to QBitArray::truncate(), whose parameter was a number of bytes in Qt 3 and a number of bits in Qt 4.
QBitArray was an explicitly shared class in Qt 3. See Explicit Sharing for more information.
The QBitVal class has been renamed QBitRef.
The QButton class has been replaced by QAbstractButton in Qt 4. Classes like QPushButton andQRadioButton inherit from QAbstractButton. As a help when porting older Qt applications, theQt3Support library contains a Q3Button class implemented in terms of the new QAbstractButton.
If you used the QButton class as a base class for your own button type and want to port your code to the newer QAbstractButton, you need to be aware that QAbstractButton has no equivalent for the Q3Button::drawButton(QPainter *) virtual function. The solution is to reimplementQWidget::paintEvent() in your QAbstractButton subclass as follows:
Q3Button function | QAbstractButton equivalent |
---|---|
Q3Button::autoResize() |
Call QWidget:setFixedSize(QWidget::sizeHint()) whenever you change the contents. |
Q3Button::isExclusiveToggle() |
Use QAbstractButton::group() orQAbstractButton::autoExclusive() instead. |
Q3Button::pixmap() const |
QAbstractButton::icon() |
Q3Button::setAutoResize() |
N/A |
Q3Button::setPixmap(const QPixmap&) |
QAbstractButton::setIcon(const QIcon &) |
Q3Button::setState(ToggleState) |
See remark below |
Q3Button::setToggleType(ToggleType) |
See remark below |
Q3Button::state() |
See remark below |
Q3Button::stateChanged(int) |
See remark below |
Q3Button::toggleType() |
See remark below |
Remarks:
See Virtual Functions for a list of QButton virtual member functions in Qt 3 that aren't virtual in Qt 4.
See Properties for a list of QButton properties in Qt 3 that have changed in Qt 4.
The QButtonGroup class has been completely redesigned in Qt 4. For compatibility, the oldQButtonGroup class has been renamed Q3ButtonGroup and has been moved to Qt3Support. Likewise, the QHButtonGroup and QVButtonGroup convenience subclasses have been renamed Q3HButtonGroupand Q3VButtonGroup and moved to the Qt3Support library.
The old QButtonGroup, as well as Q3ButtonGroup, can be used in two ways:
Unlike Q3ButtonGroup, the new QButtonGroup doesn't inherit QWidget. It is very similar to a "hiddenQ3ButtonGroup".
If you use a Q3ButtonGroup, Q3HButtonGroup, or Q3VButtonGroup as a widget and want to port to Qt 4, you can replace it with QGroupBox. In Qt 4, radio buttons with the same parent are automatically part of an exclusive group, so you normally don't need to do anything else. See also the section on QGroupBox below.
See Virtual Functions for a list of QButtonGroup virtual member functions in Qt 3 that are no longer virtual in Qt 4.
In Qt 3, QByteArray was simply a typedef for QMemArray<char>. In Qt 4, QByteArray is a class in its own right, with a higher-level API in the style of QString.
Here are the main issues to be aware of when porting to Qt 4:
For example, if you have code like
you can rewrite it as
will no longer compile. Instead, use QByteArray::operator[]:
QByteArray was an explicitly shared class in Qt 3. See Explicit Sharing for more information.
QCache<T> has been renamed Q3Cache<T> and moved to Qt3Support. The new QCache class has a different API, and takes different template parameters: QCache<Key, T>.
When porting to Qt 4, QCache<QString, T> is the obvious substitute for Q3Cache<T>. The following table summarizes the API differences.
Q3Cache<T> function | QCache<QString, T> equivalent |
---|---|
Q3Cache::Q3Cache(int maxCost, int size, bool caseSensitive) |
See remark below |
Q3Cache::autoDelete() |
N/A |
Q3Cache::count() |
QCache::count() or QCache::size() (equivalent) |
Q3Cache::setAutoDelete() |
See remark below |
Q3Cache::size() |
N/A |
Q3Cache::statistics() |
N/A |
Q3Cache::operator=() |
See remark below |
Remarks:
becomes
becomes
An alternative is to stick to using Q3Cache.
QCacheIterator<T> has been renamed Q3CacheIterator<T> and moved to the Qt3Support library. The new QCache class doesn't offer any iterator types.
The canvas module classes have been renamed and moved to the Qt3Support library.
Qt 3 class name | Compatibility class in Qt 4 |
---|---|
QCanvas |
Q3Canvas |
QCanvasEllipse |
Q3CanvasEllipse |
QCanvasItem |
Q3CanvasItem |
QCanvasItemList |
Q3CanvasItemList |
QCanvasLine |
Q3CanvasLine |
QCanvasPixmap |
Q3CanvasPixmap |
QCanvasPixmapArray |
Q3CanvasPixmapArray |
QCanvasPolygon |
Q3CanvasPolygon |
QCanvasPolygonalItem |
Q3CanvasPolygonalItem |
QCanvasRectangle |
Q3CanvasRectangle |
QCanvasSpline |
Q3CanvasSpline |
QCanvasSprite |
Q3CanvasSprite |
QCanvasText |
Q3CanvasText |
QCanvasView |
Q3CanvasView |
The Graphics View Framework replaces QCanvas. For more on porting to Graphics View, see Porting to Graphics View.
In Qt 4, QColor is a value type like QPoint or QRect. Graphics system-specific code has been implemented in QColormap.
The QColor::maxColors() function has been replaced by QColormap::size().
The QColor::numBitPlanes() function has been replaced by QColormap::depth().
The QColor::setNamedColor() function no longer supports the named color in the same way as Qt 3. Qt 4's setNamedColor() uses the new W3C convention as stated here.
Predefined Qt Colors | |||
---|---|---|---|
Qt::color0 |
Qt::color1 |
Qt::black |
Qt::white |
Qt::darkGray |
Qt::gray |
Qt::lightGray |
Qt::red |
Qt::green |
Qt::blue |
Qt::cyan |
Qt::magenta |
Qt::yellow |
Qt::darkRed |
Qt::darkGreen |
Qt::darkBlue |
Qt::darkCyan |
Qt::darkMagenta |
Qt::darkYellow |
Qt::transparent |
The predefined colors listed in the table above were static QColor objects in Qt 3. In Qt 4, they are enum values of type Qt::GlobalColor. Thanks to the implicit QColor(Qt::GlobalColor) constructor, the enum values are automatically converted to QColors in most contexts. Occasionally, you might need a cast.
For example, if you have code like
you can rewrite it as
In Qt 3, a QPalette consisted of three QColorGroup objects. In Qt 4, the (rarely used) QColorGroupabstraction has been eliminated. For source compatibility, a QColorGroup class is available whenQT3_SUPPORT is defined.
The new QPalette still works in terms of color groups, specified through enum values (QPalette::Active, QPalette::Disabled, and QPalette::Inactive). It also has the concept of acurrent color group, which you can set using QPalette::setCurrentColorGroup().
The QPalette object returned by QWidget::palette() returns a QPalette initialized with the correct current color group for the widget. This means that if you had code like
you can simply replace colorGroup() with palette():
The QColorDrag class has been renamed Q3ColorDrag and moved to the Qt3Support library. In Qt 4, use QMimeData instead and call QMimeData::setColor() to set the color.
In Qt 3, the list box used to display the contents of a QComboBox widget could be accessed by using the listBox() function. In Qt 4, the standard list box is provided by a QListView widget, and can be accessed with the view() function.
See Virtual Functions for a list of QComboBox virtual member functions in Qt 3 that are no longer virtual in Qt 4.
In Qt 3, QCString inherited from QByteArray. The main drawback of this approach is that the user had the responsibility of ensuring that the string is '\0'-terminated. Another important issue was that conversions between QCString and QByteArray often gave confusing results. (See theAchtung! Binary and Character Data article in Qt Quarterly for an overview of the pitfalls.)
Qt 4 solves that problem by merging the QByteArray and QCString classes into one class calledQByteArray. Most functions that were in QCString previously have been moved to QByteArray. The '\0' issue is handled by having QByteArray allocate one extra byte that it always sets to '\0'. For example:
The Qt3Support library contains a class called Q3CString that inherits from the new QByteArrayclass and that extends it to provide an API that is as close to the old QCString class as possible. Note that the following functions aren't provided by Q3CString:
The following functions have lost their last parameter, which specified whether the search was case sensitive or not:
In both cases, the solution is to convert the QCString to a QString and use the correspondingQString functions instead.
Also be aware that QCString::size() (inherited from QByteArray) used to return the size of the character data including the '\0'-terminator, whereas the new QByteArray::size() is just a synonym for QByteArray::length(). This brings QByteArray in line with QString.
When porting to Qt 4, occurrences of QCString should be replaced with QByteArray or QString. The following table summarizes the API differences between the Q3CString class and the Qt 4QByteArray and QString classes:
Q3CString function | Qt 4 equivalent |
---|---|
Q3CString::Q3CString(const char *, uint) |
See remark below |
Q3CString::Q3CString(int) |
QByteArray::QByteArray(int, char) |
Q3CString::leftJustify() |
QString::leftJustified() |
Q3CString::length() |
QByteArray::length() or QByteArray::size() (equivalent) |
Q3CString::lower() |
QByteArray::toLower() |
Q3CString::rightJustify() |
QString::rightJustified() |
Q3CString::setExpand() |
See remark below |
Q3CString::simplifyWhiteSpace() |
QByteArray::simplified() |
Q3CString::sprintf() |
QString::sprintf() |
Q3CString::stripWhiteSpace() |
QByteArray::trimmed() |
Q3CString::toDouble() |
QString::toDouble() |
Q3CString::toFloat() |
QString::toFloat() |
Q3CString::toInt() |
QString::toInt() |
Q3CString::toLong() |
QString::toLong() |
Q3CString::toShort() |
QString::toShort() |
Q3CString::toUInt() |
QString::toUInt() |
Q3CString::toULong() |
QString::toULong() |
Q3CString::toUShort() |
QString::toUShort() |
Q3CString::upper() |
QByteArray::toUpper() |
Remarks:
For example, if you have code like
you can rewrite it as
For example, if you have code like
you can rewrite it as
Since the old QCString class inherited from QByteArray, everything that is said in the QByteArray section applies for QCString as well.
In Qt 3, developers could create a custom event by constructing a new QCustomEvent, and send relevant data to other components in the application by passing a void pointer, either on construction or using the setData() function. Objects could receive custom events by reimplementing the customEvent() function, and access the stored data using the event's data() function.
In Qt 4, custom events are created by subclassing QEvent. Event-specific data can be stored in a way that is appropriate for your application. Custom events are still delivered to each object'scustomEvent() handler function, but as QEvent objects rather than as deprecated QCustomEventobjects.
The QDataBrowser class has been renamed Q3DataBrowser and moved to the Qt3Support library. In Qt 4.2, you should use the QDataWidgetMapper class to create data-aware forms.
See QtSql Module for an overview of the new SQL classes.
The QDataPump class was used internally in Qt 2.x in conjunction with QImageConsumer. It was obsoleted in Qt 3.0.
If you use this mechanism in your application, please submit a report to the Task Tracker on the Qt website and we will try to find a satisfactory substitute.
The QDataSink class was used internally in Qt 2.x in conjunction with QImageConsumer. It was obsoleted in Qt 3.0.
If you use this mechanism in your application, please submit a report to the Task Tracker on the Qt website and we will try to find a satisfactory substitute.
The QDataSource class was used internally in Qt 2.x in conjunction with QImageConsumer. It was obsoleted in Qt 3.0. If you use this mechanism in your application, please submit a report to theTask Tracker on the Qt website and we will try to find a satisfactory substitute.
The QDataTable class has been renamed Q3DataTable and moved to the Qt3Support library. In Qt 4.2, you should use the QDataWidgetMapper class to create data-aware forms.
See QtSql Module for an overview of the new SQL classes.
The QDataView class has been renamed Q3DataView and moved to the Qt3Support library. In Qt 4.2, you should use the QDataWidgetMapper class to create data-aware forms.
See QtSql Module for an overview of the new SQL classes.
The QDateEdit class in Qt 4 is a convenience class based on QDateTimeEdit. The old class has been renamed Q3DateEdit and moved to the Qt3Support library.
See Virtual Functions for a list of QDateEdit virtual member functions in Qt 3 that are no longer virtual in Qt 4.
The QDateTimeEditBase class has been renamed Q3DateTimeEditBase and moved to Qt3Support. Use QDateTimeEdit or QAbstractSpinBox instead.
The old QDateTimeEdit class has been renamed Q3DateTimeEditBase and moved to Qt3Support. The new QDateTimeEdit in Qt 4 has been rewritten from scratch to provide a more flexible and powerful API.
See Virtual Functions for a list of QDateTimeEdit virtual member functions in Qt 3 that are no longer virtual in Qt 4.
The QDeepCopy<T> class in Qt 3 provided a means of ensuring that implicitly shared and explicitly shared classes referenced unique data. This was necessary because the reference counting in Qt's container classes was done in a thread-unsafe manner.
With Qt 4, QDeepCopy<T> has been renamed Q3DeepCopy<T> and moved to the Qt3Support library. Removing it from existing code is straightforward.
For example, if you have code like
you can rewrite it as
See Virtual Functions for a list of QDial virtual member functions in Qt 3 that are no longer virtual in Qt 4.
See Properties for a list of QDial properties in Qt 3 that have changed in Qt 4.
QDict<T> has been renamed Q3Dict<T> and moved to Qt3Support. It has been replaced by the more modern QHash<Key, T> and QMultiHash<Key, T> classes.
When porting old code that uses QDict<T> to Qt 4, there are four classes that you can use:
Qt 4 class | When to use it |
---|---|
QMultiHash<QString, T *> |
Since Q3Dict<T> is pointer-based and allows duplicate keys, this is usually the most straightforward conversion. |
QMultiHash<QString, T> |
If type T is an assignable data type, you can use T as the value type rather than T *. This often leads to nicer code. |
QHash<QString, T *> |
If you don't use duplicate keys, you can use QHash instead of QMultiHash.QMultiHash inherits from QHash. |
QHash<QString, T> |
The APIs of Q3Dict<T> and QMultiHash<QString, T *> are quite similar. The main issue is thatQ3Dict supports auto-delete whereas QMultiHash doesn't.
The following table summarizes the API differences between the two classes:
Q3Dict function | QMultiHash equivalent |
---|---|
Q3Dict::Q3Dict(int size, bool caseSensitive) |
See remarks below |
Q3Dict::autoDelete() |
N/A |
Q3Dict::count() |
QMultiHash::count() or QMultiHash::size() (equivalent) |
Q3Dict::find(const QString &) |
QMultiHash::value(const QString &) |
Q3Dict::remove(const QString &) |
QMultiHash::take(const QString &) |
Q3Dict::resize(uint) |
QMultiHash::reserve(int) |
Q3Dict::setAutoDelete() |
See discussion below |
Q3Dict::size() |
QMultiHash::capacity() |
Q3Dict::statistics() |
N/A |
Q3Dict::operator[](const QString &) |
See remark below |
Remarks:
If you use Q3Dict's auto-delete feature (by calling Q3Dict::setAutoDelete(true)), you need to do some more work. You have two options: Either you call delete yourself whenever you remove an item from the container, or you use QMultiHash<QString, T> instead of QMultiHash<QString, T *> (i.e. store values directly instead of pointers to values). Here, we'll see when to call delete.
The following table summarizes the idioms that you need to watch out for if you want to call deleteyourself.
Q3Dict idiom | QMultiHash idiom |
---|---|
|
|
|
|
(also called from Q3Dict's destructor)
|
In 99% of cases, the following idiom also works: However, it may lead to crashes if hash is referenced from the value type's destructor, because hash contains dangling pointers until clear() is called.
|
Be aware that Q3Dict's destructor automatically calls clear(). If you have a Q3Dict data member in a custom class and use the auto-delete feature, you will need to call delete on all the items in the container from your class destructor to avoid a memory leak.
Finally, QDictIterator<T> (renamed Q3DictIterator<T>) must also be ported. There are no fewer than four iterator classes that can be used as a replacement: QHash::const_iterator,QHash::iterator, QHashIterator, and QMutableHashIterator. The most straightforward class to use when porting is QHashIterator<QString, T *>. The following table summarizes the API differences:
Q3DictIterator functions | Qt 4 equivalent |
---|---|
Q3DictIterator::count() |
QHash::count() or QHash::size() |
Q3DictIterator::current() |
QHashIterator::value() |
Q3DictIterator::currentKey() |
QHashIterator::key() |
Q3DictIterator::isEmpty() |
QHash::isEmpty() |
Q3DictIterator::toFirst() |
QHashIterator::toFront() |
Q3DictIterator::operator()() |
QHashIterator::value() |
Q3DictIterator::operator*() |
QHashIterator::value() |
Q3DictIterator::operator++() |
See remark below |
Be aware that QHashIterator has a different way of iterating than Q3DictIterator. A typical loop with Q3DictIterator looks like this:
Here's the equivalent QHashIterator loop:
See Java-style iterators for details.
The following functions used to have a boolean acceptAbsPath parameter that defaulted to true:
In Qt 3, if acceptAbsPath is true, a file name starting with '/' is be returned without change; ifacceptAbsPath is false, an absolute path is prepended to the file name. For example:
Current directory | File name | acceptAbsPath | File path |
---|---|---|---|
/home/tsmith |
index.html |
true |
/home/tsmith/index.html |
false |
/home/tsmith/index.html |
||
/home/tsmith |
/index.html |
true |
/index.html |
false |
/home/tsmith/index.html |
In Qt 4, this parameter is no longer available. If you use it in your code, you can check thatQDir::isRelativePath() returns false instead.
For example, if you have code like
you can rewrite it as
QDir::encodedEntryList() has been removed.
fileInfoList(), entryInfoList(), and drives() now return a QList<QFileInfo> and not a QPtrList<QFileInfo> *. Code using these methods will not work with the Qt3Support library and must be adapted instead.
See Virtual Functions for a list of QDir virtual member functions in Qt 3 that are no longer virtual in Qt 4.
QDir::match() now always matches case insensitively.
QDir::homeDirPath() has been removed. Use QDir::home() instead, and extract the path separately.
Qt 3 used its own implementation of the DNS protocol and provided a low-level QDns class. Qt 4'sQHostInfo class uses the system's gethostbyname() function from a thread instead.
The old QDns class has been renamed Q3Dns and moved to the Qt3Support library. The newQHostInfo class has a radically different API: It consists mainly of two static functions, one of which is blocking (QHostInfo::fromName()), the other non-blocking (QHostInfo::lookupHost()). See the QHostInfo class documentation for details.
The QDockArea class has been renamed Q3DockArea and moved to the Qt3Support library. In Qt 4,QMainWindow handles the dock and toolbar areas itself. See the QMainWindow documentation for details.
The old QDockWindow class has been renamed Q3DockWindow and moved to the Qt3Support library. In Qt 4, there is a new QDockWidget class with a different API. See the class documentation for details.
See Virtual Functions for a list of QDockWidget virtual member functions in Qt 3 that are no longer virtual in Qt 4.
Note: Q3DockWindow's horizontallyStretchable property can be achieved in QDockWidget with size policies.
The QDragObject class has been renamed Q3DragObject and moved to the Qt3Support library. In Qt 4, it has been replaced by the QMimeData class. See the class documentation for details.
Note that the Q3DragObject::DragCopyOrMove drag and drop mode is interpreted differently to Qt 3's QDragObject::DragCopyOrMove mode. In Qt 3, a move operation was performed by default, and the user had to hold down the Ctrl key to perform a copy operation. In Qt 4, a copy operation is performed by default; the user has to hold down the Shift key to perform a move operation.
See Porting to Qt 4 - Drag and Drop for a comparison between the drag and drop APIs in Qt 3 and Qt 4.
The QDropSite class has been renamed Q3DropSite and moved to the Qt3Support library.
The QDropSite class has been obsolete ever since Qt 2.0. The only thing it does is call QWidget::setAcceptDrops(true).
For example, if you have code like
you can rewrite it as
See Porting to Qt 4 - Drag and Drop for a comparison between the drag and drop APIs in Qt 3 and Qt 4.
The QEditorFactory class has been renamed Q3EditorFactory and moved to the Qt3Support library.
See QtSql Module for an overview of the new SQL classes.
In Qt 3, QEventLoop combined the Qt event loop and the event dispatching. In Qt 4, these tasks are now assigned to two distinct classes: QEventLoop and QAbstractEventDispatcher.
If you subclassed QEventLoop to integrate with another library's event loop, you must subclassQAbstractEventDispatcher instead. See the class documentation for details.
Developers using QEventLoop::loopLevel() in Qt 3 should use QCoreApplication::loopLevel() instead. Note that this function is marked as obsolete, but it is expected to be available for the lifetime of Qt 4.
The QFileDialog class in Qt 4 has been totally rewritten. It provides most of the functionality of the old QFileDialog class, but with a different API. Some functionality, such as the ability to preview files, is expected to be added in a later Qt 4 release.
The old QFileDialog, QFileIconProvider, and QFilePreview classes has been renamed Q3FileDialog,Q3FileIconProvider, and Q3FilePreview and have been moved to Qt3Support. You can use them if you need some functionality not provided yet by the new QFileDialog class.
The following table lists which functions have been renamed or removed in Qt 4.
Old function | Qt 4 equivalent |
---|---|
Q3FileDialog::addFilter(const QString &) |
See remark below |
Q3FileDialog::addLeftWidget(QWidget *) |
N/A |
Q3FileDialog::addRightWidget(QWidget *) |
N/A |
Q3FileDialog::addToolButton(QAbstractButton *, bool separator) |
N/A |
Q3FileDialog::addWidgets(QLabel *, QWidget *,QPushButton *) |
N/A |
Q3FileDialog::dir() |
QFileDialog::directory() |
Q3FileDialog::dirPath() |
QFileDialog::directory().path() |
Q3FileDialog::iconProvider() |
N/A |
Q3FileDialog::isContentsPreviewEnabled() |
N/A |
Q3FileDialog::isInfoPreviewEnabled() |
N/A |
Q3FileDialog::previewMode() |
N/A |
Q3FileDialog::rereadDir() |
N/A |
Q3FileDialog::resortDir() |
N/A |
Q3FileDialog::selectAll(bool) |
N/A |
Q3FileDialog::setContentsPreview(QWidget *,Q3FilePreview *) |
N/A |
Q3FileDialog::setContentsPreviewEnabled(bool) |
N/A |
Q3FileDialog::setDir(const QString &) |
QFileDialog::setDirectory(const QString&) |
Q3FileDialog::setFilters(const char **) |
Q3FileDialog::setFilters(const QStringList&) |
Q3FileDialog::setIconProvider(Q3FileIconProvider *) |
N/A |
Q3FileDialog::setInfoPreview(QWidget *,Q3FilePreview *) |
N/A |
Q3FileDialog::setInfoPreviewEnabled(bool) |
N/A |
Q3FileDialog::setPreviewMode(PreviewMode) |
N/A |
Q3FileDialog::setSelectedFilter(const QString &) |
QFileDialog::selectFilter(const QString &) |
Q3FileDialog::setSelectedFilter(int) |
See remark below |
Q3FileDialog::setSelection(const QString &) |
QFileDialog::selectFile(const QString &) |
Q3FileDialog::setShowHiddenFiles(bool) |
showHidden() |
Q3FileDialog::setUrl(const QUrlOperator &) |
N/A |
Q3FileDialog::showHiddenFiles() |
N/A |
Q3FileDialog::url() |
QUrl::fromLocalFile(QFileDialog::directory()) |
Old signals | Qt 4 equivalent |
Q3FileDialog::fileHighlighted(const QString &) |
N/A |
Q3FileDialog::fileSelected(const QString &) |
QFileDialog::filesSelected(constQStringList &) |
Q3FileDialog::dirEntered(const QString &) |
N/A |
Q3FileDialog::filterSelected(const QString &) |
N/A |
Remarks:
For example, if you have code like
you can rewrite it as
For example, if you have code like
you can rewrite it as
There are no equivalent virtual functions to the two Q3FileDialog::setSelectedFilter() virtual functions in the QFileDialog API. In addition, these functions have been renamed or removed, as described above.
The QFocusData class is not available in Qt 4. Some of its functionality is available via theQWidget::nextInFocusChain() and QWidget::focusNextPrevChild() functions.
The setReason() function is no longer present in Qt 4. It is necessary to define the reason when constructing a focus event.
QFont::Script has been moved to QFontDatabase::WritingSystem.
The QFrame class has been made more lightweight in Qt 4, by reducing the number of properties and virtual functions. The reduction in the number of virtual functions is significant becauseQFrame is the base class of many Qt classes.
Here's an overview of the changes:
To help with porting, the Qt3Support library contains a Q3Frame class that inherits QFrame and provides a similar API to the old QFrame class. If you derived from QFrame in your application, you might want to use Q3Frame as a base class as a first step in the porting process, and later move on to the new QFrame class.
See Virtual Functions for a list of QFrame virtual member functions in Qt 3 that are no longer virtual in Qt 4.
QFtp no longer inherits from QNetworkProtocol. See the section on QNetworkProtocol for details.
The old QFtp class has been renamed Q3Ftp and moved to the Qt3Support library.
The QGLayoutIterator class no longer exists in Qt 4. This makes only a difference if you implemented custom layout managers (i.e., QLayout subclasses).
The new approach is much simpler: It consists in reimplementing QLayout::itemAt() andQLayout::takeAt(). These functions operate on indexes, eliminating the need for a layout iterator class.
The QGrid class is now only available as Q3Grid in Qt 4. You can achieve the same result as QGridby creating a QWidget with a grid layout:
For example, if you have code like
you can rewrite it as
See Virtual Functions for a list of QGridLayout virtual member functions in Qt 3 that are no longer virtual in Qt 4.
The QGridView class has been renamed Q3GridView and moved to the Qt3Support library. In Qt 4, we recommend that you use QTableView or QAbstractItemView for presenting tabular data.
See Model/View Programming for an overview of the new item view classes.
The QGroupBox class has been redesigned in Qt 4. Many of the features of the old QGroupBox class can be obtained by using the Q3GroupBox class from the Qt3Support library.
The new QGroupBox is more lightweight. It doesn't attempt to duplicate functionality already provided by QGridLayout, and it does not inherit from QFrame. As a result, the following members have been removed:
Naturally, the columns and orientation properties have also been removed.
If you rely on some of the missing functionality in your application, you can use Q3GroupBoxinstead of QGroupBox as a help to porting.
See Virtual Functions for a list of QGroupBox virtual member functions in Qt 3 that are no longer virtual in Qt 4.
The QHBox class is now only available as Q3HBox in Qt 4. You can achieve the same result as QHBoxby creating a QWidget with an horizontal layout:
For example, if you have code like
you can rewrite it as
Note that child widgets are not automatically placed into the widget's layout; you will need to manually add each widget to the QHBoxLayout.
The QHeader class has been renamed Q3Header and moved to the Qt3Support library. In Qt 4, it is replaced by the QHeaderView class.
See Model/View Programming for an overview of the new item view classes.
The QHGroupBox class has been renamed Q3HGroupBox and moved to the Qt3Support library. Qt 4 does not provide a specific replacement class for QHGroupBox since QGroupBox is designed to be a generic container widget. As a result, you need to supply your own layout for any child widgets.
See #QGroupBox for more information about porting code that uses group boxes.
QHttp no longer inherits from QNetworkProtocol. See the See the section on QNetworkProtocol for details.
The old QHttp, QHttpHeader, QHttpRequestHeader, and QHttpResponseHeader classes have been renamed Q3Http, Q3HttpHeader, Q3HttpRequestHeader, and Q3HttpResponseHeader and have been moved to the Qt3Support library.
The QIconFactory class is no longer part of Qt. It has been replaced by the QIconEngine class.
The QIconSet class is no longer part of Qt. It has been replaced by the QIcon class.
The QIconView, QIconViewItem, QIconDrag, and QIconDragItem classes has been renamed Q3IconView,Q3IconViewItem, Q3IconDrag, and Q3IconDragItem and moved to the Qt3Support library. New Qt applications should use QListWidget or its base class QListView instead, and call QListView::setViewMode(QListView::IconMode) to obtain an "icon view" look.
See Model/View Programming for an overview of the new item view classes.
The QImageDrag class has been renamed Q3ImageDrag and moved to the Qt3Support library. In Qt 4, use QMimeData instead and call QMimeData::setImage() to set the image.
See Porting to Qt 4 - Drag and Drop for a comparison between the drag and drop APIs in Qt 3 and Qt 4.
The QImageIO class has been split into two classes: QImageReader and QImageWriter. The table below shows the correspondance between the two APIs:
Qt 3 function | Qt 4 equivalents |
---|---|
QImageIO::description() |
QImageWriter::text() |
QImageIO::fileName() |
QImageReader::fileName() and QImageWriter::fileName() |
QImageIO::format() |
QImageReader::format() and QImageWriter::format() |
QImageIO::gamma() |
QImageWriter::gamma() |
QImageIO::image() |
Return value of QImageReader::read() |
QImageIO::inputFormats() |
QImageReader::supportedImageFormats() |
QImageIO::ioDevice() |
QImageReader::device() and QImageWriter::device() |
QImageIO::outputFormats() |
QImageWriter::supportedImageFormats() |
QImageIO::parameters() |
N/A |
QImageIO::quality() |
QImageWriter::quality() |
QImageIO::read() |
QImageReader::read() |
QImageIO::setDescription() |
QImageWriter::setText() |
QImageIO::setFileName() |
QImageReader::setFileName() and QImageWriter::setFileName() |
QImageIO::setFormat() |
QImageReader::setFormat() and QImageWriter::setFormat() |
QImageIO::setGamma() |
QImageWriter::setGamma() |
QImageIO::setIODevice() |
QImageReader::setDevice() and QImageWriter::setDevice() |
QImageIO::setImage() |
Argument to QImageWriter::write() |
QImageIO::setParameters() |
N/A |
QImageIO::setQuality() |
QImageWriter::setQuality() |
QImageIO::setStatus() |
N/A |
QImageIO::status() |
QImageReader::error() and QImageWriter::error() |
QImageIO::write() |
QImageWriter::write() |
QIntCache<T> has been moved to Qt3Support. It has been replaced by QCache<int, T>.
For details, read the section on QCache<T>, mentally substituting int for QString.
QIntDict<T> and QIntDictIterator<T> have been moved to Qt3Support. They have been replaced by the more modern QHash<Key, T> and QMultiHash<Key, T> classes and their associated iterator classes.
When porting old code that uses QIntDict<T> to Qt 4, there are four classes that you can use:
For details, read the section on QDict<T>, mentally substituting int for QString.
The QIODevice class's API has been simplified to make it easier to subclass and to make it work more smoothly with asynchronous devices such as QTcpSocket and QProcess.
The following virtual functions have changed name or signature:
Qt 3 function | Comment |
---|---|
QIODevice::at() const |
Renamed QIODevice::pos(). |
QIODevice::at(Offset) |
Renamed QIODevice::seek(). |
QIODevice::open(int) |
The parameter is now of typeQIODevice::OpenMode. |
QIODevice::readBlock(char *, Q_ULONG) |
QIODevice::read(char *, qint64) |
QIODevice::writeBlock(const char *,Q_ULONG) |
QIODevice::write(const char *, qint64) |
Note: QIODevice::open(QIODevice::OpenMode) is no longer pure virtual.
The following functions are no longer virtual or don't exist anymore:
QIODevice::getch() |
Renamed QIODevice::getChar() and implemented in terms ofQIODevice::readData(). |
QIODevice::putch(int) |
Renamed QIODevice::putChar() and implemented in terms ofQIODevice::writeData(). |
QIODevice::readAll() |
Implemented in terms of QIODevice::readData(). |
QIODevice::readLine(char *,Q_ULONG) |
Implemented in terms of QIODevice::readData() |
QIODevice::ungetch(int) |
Renamed QIODevice::ungetChar() and simulated using an internal unget buffer. |
The IO_xxx flags have been revised, and the protected setFlags() function removed. Most of the flags have been eliminated because errors are best handled by implementing certain functions inQIODevice subclasses rather than through the base classes. The file access flags, such asIO_ReadOnly and IO_WriteOnly, have been moved to the QIODevice class to avoid polluting the global namespace. The table below shows the correspondence between the Qt 3 IO_xxx flags and the Qt 4 API:
Qt 3 constant | Qt 4 equivalent |
---|---|
IO_Direct |
Use !QIODevice::isSequential() instead (notice the not). |
IO_Sequential |
Use QIODevice::isSequential() instead. |
IO_Combined |
N/A |
IO_TypeMask |
N/A |
IO_Raw |
QIODevice::Unbuffered |
IO_Async |
N/A |
IO_ReadOnly |
QIODevice::ReadOnly |
IO_WriteOnly |
QIODevice::WriteOnly |
IO_ReadWrite |
QIODevice::ReadWrite |
IO_Append |
QIODevice::Append |
IO_Truncate |
QIODevice::Truncate |
IO_Translate |
QIODevice::Text |
IO_ModeMask |
N/A |
IO_Open |
Use QIODevice::isOpen() instead. |
IO_StateMask |
N/A |
IO_Ok |
N/A |
IO_ReadError |
N/A |
IO_WriteError |
N/A |
IO_FatalError |
N/A |
IO_ResourceError |
N/A |
IO_OpenError |
N/A |
IO_ConnectError |
N/A |
IO_AbortError |
N/A |
IO_TimeOutError |
N/A |
IO_UnspecifiedError |
N/A |
The QIODeviceSource class was used internally in Qt 2.x in conjunction with QImageConsumer. It was obsoleted in Qt 3.0. If you use this mechanism in your application, please submit a report to the Task Tracker on the Qt website and we will try to find a satisfactory substitute.
QLabel doesn't enable word-wrap automatically anymore when rich text is used. You can enable it by calling QLabel::setWordWrap() or by setting the wordWrap property. The reason for this change is that the old behavior was confusing to many users.
Also, QLabel no longer offers an autoResize property. Instead, you can call QWidget::setFixedSize() on the label, with QLabel::sizeHint() as the argument, whenever you change the contents of theQLabel.
See also Virtual Functions for a list of QLabel virtual member functions in Qt 3 that are no longer virtual in Qt 4.
In Qt 4, margins are always handled by layouts; there is no QLayout::setSupportsMargin() function anymore.
The deleteAllItems() function is now only available if QT3_SUPPORT is defined. If you maintain a QListof layout items, you can use qDeleteAll() to remove all the items in one go.
In Qt 3, it was possible to change the resizing behavior for layouts in top-level widgets by adjusting the layout's resizeMode property. In Qt 4, this property has been replaced by theQLayout::sizeConstraint property which provides more control over how the layout behaves when resized.
See also the section on QLayoutIterator and the section on QGLayoutIterator.
The QLayoutIterator class is obsoleted in Qt 4. It is available only if QT3_SUPPORT is defined. It can be replaced by the QLayout::itemAt() and QLayout::takeAt() functions, which operate on indexes.
For example, if you have code like
you can rewrite it as
See Properties for a list of QLineEdit properties in Qt 3 that have changed in Qt 4.
The default value of QLineEdit's dragEnabled property was true in Qt 3. In Qt 4, the default value is false.
Note that QLineEdit in Qt 4 is no longer a subclass of QFrame. If you need to visually style a line edit with a frame, we recommend either using a QFrame as a container for a QLineEdit or customizing the line edit with a style sheet.
The QListBox, QListBoxItem, QListBoxText, and QListBoxPixmap classes have been renamedQ3ListBox, Q3ListBoxItem, Q3ListBoxText, and Q3ListBoxPixmap and have been moved to theQt3Support library. New Qt applications should use QListWidget or its base class QListView instead.
See Model/View Programming for an overview of the new item view classes.
The QListView, QListViewItem, QCheckListItem, and QListViewItemIterator classes have been renamed Q3ListView, Q3ListViewItem, Q3CheckListItem, and Q3ListViewItemIterator, and have been moved to the Qt3Support library. New Qt applications should use one of the following four classes instead: QTreeView or QTreeWidget for tree-like structures; QListWidget or the newQListView class for one-dimensional lists.
See Model/View Programming for an overview of the new item view classes.
The QLocalFs class is no longer part of the public Qt API. It has been renamed Q3LocalFs and moved to Qt3Support. Use QDir, QFileInfo, or QFile instead.
The QMainWindow class has been redesigned in Qt 4 to provide a more modern look and feel and more flexibility. The API has changed to reflect that. The old QMainWindow class has been renamedQ3MainWindow and moved to Qt3Support. See the QMainWindow class documentation for details.
QMemArray<T> has been moved to Qt3Support. It has been replaced by the QVector<T> class.
The following table summarizes the API differences between the two classes.
QMemArray::assign(const QMemArray<T> &) |
QVector::operator=() |
QMemArray::assign(const T *, uint) |
See remark below |
QMemArray::duplicate(const QMemArray &) |
QVector::operator=() |
QMemArray::duplicate(const T *, uint) |
See remark below |
QMemArray::setRawData(const T *, uint) |
N/A |
QMemArray::resetRawData(const T *, uint) |
N/A |
QMemArray::find(const T &, uint) |
QVector::indexOf(const T &, int) |
QMemArray::contains(const T &) |
QVector::count(const T &) |
QMemArray::sort() |
qSort() |
QMemArray::bsearch(const T &d) |
qBinaryFind() |
QMemArray::at(uint) |
QVector::operator[]() |
QMemArray::operator const T *() |
QVector::constData() |
Remarks:
For example, if you have code like
you can rewrite it as
In Qt 3, QMenuBar inherited from QFrame and QMenuData; in Qt 4, it is a direct subclass ofQWidget. Applications that provided customized menu bars will need to take advantage of the styling features described in the Qt Style Sheets document.
It is not possible to add widgets to menu bars in Qt 4.
In Qt 4, the QMenu class provides a menu widget that can be used in all the places where menus are used in an application. Unlike QMenuData, QMenu is designed around the concept of actions, provided by the QAction class, instead of the identifiers used in Qt 3.
In Qt 3, it was possible to insert widgets directly into menus by using a specificQMenuData::insertItem() overload. In Qt 4.2 and later, the QWidgetAction class can be used to wrap widgets for use in Qt 4's action-based APIs.
The QMessageBox::iconPixmap() function used to return a "const QPixmap *". In Qt 4, it returns aQPixmap.
The QMimeSourceFactory has been renamed Q3MimeSourceFactory and moved to the Qt3Supportlibrary. New Qt applications should use Qt 4's Resource System instead.
The QMovie API has been revised in Qt 4 to make it more consistent with the other Qt classes (notably QImageReader). The table below summarizes the changes.
Qt 3 function | Qt 4 equivalent |
---|---|
QMovie::connectResize() |
Connect to QMovie::resized() |
QMovie::connectStatus() |
Connect to QMovie::stateChanged() |
QMovie::connectUpdate() |
Connect to QMovie::updated() |
QMovie::disconnectResize() |
Disconnect from QMovie::resized() |
QMovie::disconnectStatus() |
Disconnect from QMovie::stateChanged() |
QMovie::disconnectUpdate() |
Disconnect from QMovie::updated() |
QMovie::finished() |
Use QMovie::state() instead |
QMovie::frameImage() |
Use QMovie::currentImage() instead |
QMovie::frameNumber() |
Use QMovie::currentFrameNumber() instead |
QMovie::framePixmap() |
Use QMovie::currentPixmap() instead |
QMovie::getValidRect() |
Use frameRect() instead |
QMovie::isNull() |
Use QMovie::isValid() instead |
QMovie::pause() |
Use QMovie::setPaused(true) instead |
QMovie::paused() |
Use QMovie::state() instead |
QMovie::pushData() |
N/A |
QMovie::pushSpace() |
N/A |
QMovie::restart() |
Use QMovie::jumpToFrame(0) instead |
QMovie::running() |
Use QMovie::state() instead |
QMovie::step() |
Use QMovie::jumpToFrame() and QMovie::setPaused() instead |
QMovie::step() |
Use QMovie::jumpToNextFrame() instead |
QMovie::steps() |
Use QMovie::currentFrameNumber() and QMovie::frameCount() instead |
QMovie::unpause() |
Use QMovie::setPaused(false) instead |
The QMultiLineEdit class in Qt 3 was a convenience QTextEdit subclass that provided an interface compatible with Qt 2's QMultiLineEdit class. In Qt 4, it is called Q3MultiLineEdit, it inheritsQ3TextEdit, and it is part of Qt3Support. Use QTextEdit in new code.
The QNetworkProtocol, QNetworkProtocolFactoryBase, QNetworkProtocolFactory<T>, and QNetworkOperation classes are no longer part of the public Qt API. They have been renamedQ3NetworkProtocol, Q3NetworkProtocolFactoryBase, Q3NetworkProtocolFactory<T>, andQ3NetworkOperation and have been moved to the Qt3Support library.
In Qt 4 applications, you can use classes like QFtp and QNetworkAccessManager directly to perform file-related actions on a remote host.
QObject::children() now returns a QObjectList instead of a pointer to a QObjectList. See also the comments on QObjectList below.
Use QObject::findChildren() (or qFindChildren() if you need MSVC 6 compatibility) instead of QObject::queryList(). For example:
QObject::killTimers() has been removed because it was unsafe to use in subclass. (A subclass normally doesn't know whether the base class uses timers or not.)
The QObject::name property has been renamed QObject::objectName.
QObject::objectTrees() has been removed. If you are primarly interested in widgets, useQApplication::allWidgets() or QApplication::topLevelWidgets().
The QObjectDictionary class is a synonym for QAsciiDict<QMetaObject>. See the section on QAsciiDict<T>.
In Qt 3, the QObjectList class was a typedef for QPtrList<QObject>. In Qt 4, it is a typedef forQList<QObject *>. See the section on QPtrList<T>.
To reimplement painter backends one previously needed to reimplement the virtual function QPaintDevice::cmd(). This function is taken out and should is replaced with the functionQPaintDevice::paintEngine() and the abstract class QPaintEngine. QPaintEngine provides virtual functions for all drawing operations that can be performed on a painter backend.
bitBlt() and copyBlt() are now only compatibility functions. Use QPainter::drawPixmap() instead.
All functions that used to be provided by the QPaintDeviceMetrics class have now been moved toQPaintDevice.
For example, if you have code like
you can rewrite it as
For compatibility, the old QPaintDeviceMetrics class has been renamed Q3PaintDeviceMetrics and moved to Qt3Support.
The QPainter class has undergone some changes in Qt 4 because of the way rectangles are drawn. In Qt 4, the result of drawing a QRect with a pen width of 1 pixel is 1 pixel wider and 1 pixel taller than in Qt 3.
For compatibility, we provide a Q3Painter class in Qt3Support that provides the old semantics. See the Q3Painter documentation for details and for the reasons why we had to make this change.
The QPainter::CoordinateMode enum has been removed in Qt 4. All clipping operations are now defined using logical coordinates and are subject to transformation operations.
The QPainter::RasterOP enum has been replaced with QPainter::CompositionMode.
In Qt 3, a QPicture could be saved in the SVG file format. In Qt 4, the SVG support is provided by the QtSvg module, which includes classes for displaying the contents of SVG files.
If you would like to generate SVG files, you can use the Q3Picture compatibility class or theQSvgGenerator class introduced in Qt 4.3.
The mask() function has been changed to return a reference to a QBitmap rather than a pointer. As a result, it is no longer possible simply to test for a null pointer when determining whether a pixmap ha