ホーム · All Namespaces · 全てのクラス · メインのクラス · グループ別 · Modules · 関数一覧

[Previous: Porting Guides] [Contents] [Next: Porting to Qt 4 - Virtual Functions]

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 を見てください。また Moving from Qt 3 to Qt 4 には Qt 4 に移植しやすい Qt 3 のコードの書き方があります。

Other porting guides:

Qt 4 には Qt 3 に対するバイナリ互換がありません。これは Qt 3 用にコンパイルされたプログラムは Qt 4 で再コンパイルしなければならないことを意味します。さらに Qt 4 は Qt 3 に対して ソース compatible 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.

コードを Qt 3 から Qt 4 へ移植する:

  1. Briefly read the porting notes below to get an idea of what to expect.
  2. Be sure that your code compiles and runs well on all your target platforms with Qt 3.
  3. Add the line QT += qt3support to your .pro file if you use qmake; otherwise, edit your makefile or project file to link against the Qt3Support library and add -DQT3_SUPPORT to your compiler flags. (You might also need to specify other libraries. See What's New in Qt 4 for details.)
  4. Run the qt3to4 porting tool. The tool will go through your source code and adapt it to Qt 4.
  5. Follow the instructions in the Porting .ui Files to Qt 4 page to port Qt Designer files.
  6. Recompile with Qt 4. For each error, search below for related identifiers (e.g., function names, class names). This document mentions all relevant identifiers to help you get the information you need at the cost of being a little verbose.

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 a QString::simplifyWhiteSpace() compatibility function that's implemented inline and that simply calls QString::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 define QT3_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:

Casting and Object Types

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 QFrame pointer so that the instance's functions can be accessed.

In Qt 4, much of this functionality is provided by the qobject_cast() function, and additional functions also provide similar functionality for certain non-QObject types:

Qt 3 functionQt 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 &)

Type Names

The table below lists the classes that have been renamed in Qt 4. If you compile your applications with QT3_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 class nameQt 4 class name
QIconSetQIcon
QWMatrixQMatrix
QGuardedPtrQPointer

The table below lists the enums and typedefs that have been renamed in Qt 4. If you compile your applications with QT3_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 nameQt 4 type name
QApplication::ColorModeQApplication::ColorSpec
QButton::ToggleStateQCheckBox::ToggleState
QCursorShapeQt::CursorShape
QFile::FilterSpecQFile::Filters
QFile::PermissionSpecQFile::Permission
QFile::SortSpecQFile::SortFlags
QFile::StatusQFile::Error
QFileInfo::PermissionSpecQFile::Permission
QGrid::DirectionQt::Orientation
QGridWidget::DirectionQt::Orientation
QIODevice::Offsetqlonglong
QImage::ScaleModeQt::AspectRatioMode
QSize::ScaleModeQt::AspectRatioMode
QSocket::ErrorQ3Socket::Error
QSocket::StateQ3Socket::State
QStyle::SCFlagsQStyle::SubControls
QStyle::SFlagsQStyle::State
QTSQTextStream
QUrlDragQUriDrag
QWidget::FocusPolicyQt::FocusPolicy
Q_LLONGqlonglong
Q_ULLONGqulonglong
Qt::DockQt::ToolBarDock
Qt::MacintoshVersionQSysInfo::MacVersion
Qt::TextFlagsQt::TextFlag
Qt::WindowsVersionQSysInfo::WinVersion

Enum Values

The table below lists the enum values that have been renamed in Qt 4. If you compile your applications with QT3_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 nameQt 4 enum value name
IO_AppendQIODevice::Append
IO_ReadOnlyQIODevice::ReadOnly
IO_ReadWriteQIODevice::ReadWrite
IO_TranslateQIODevice::Text
IO_TruncateQIODevice::Truncate
IO_WriteOnlyQIODevice::WriteOnly
IO_RawQIODevice::Unbuffered
QAccessible::MoveableQAccessible::Movable
QApplication::CustomColorsQApplication::CustomColor
QApplication::NormalColorsQApplication::NormalColor
QButton::NoChangeQCheckBox::NoChange
QButton::OffQCheckBox::Off
QButton::OnQCheckBox::On
QChar::SingleQChar::NoDecomposition
QChar::byteOrderMarkQChar::ByteOrderMark
QChar::byteOrderSwappedQChar::ByteOrderSwapped
QChar::nbspQChar::Nbsp
QChar::nullQChar::Null
QChar::replacementQChar::ReplacementCharacter
QComboBox::AfterCurrentQComboBox::InsertAfterCurrent
QComboBox::AtBottomQComboBox::InsertAtBottom
QComboBox::AtCurrentQComboBox::InsertAtCurrent
QComboBox::AtTopQComboBox::InsertAtTop
QComboBox::BeforeCurrentQComboBox::InsertBeforeCurrent
QComboBox::NoInsertionQComboBox::NoInsert
QDir::DefaultFilterQDir::NoFilter
QDir::DefaultSortQDir::NoSort
QEvent::AccelQEvent::Shortcut
QEvent::AccelOverrideQEvent::ShortcutOverride
QEvent::CaptionChangeQEvent::WindowTitleChange
QEvent::ChildInsertedQEvent::ChildAdded
QEvent::IMComposeQEvent::InputMethodCompose
QEvent::IMEndQEvent::InputMethodEnd
QEvent::IMStartQEvent::InputMethodStart
QEvent::IconChangeQEvent::WindowIconChange
QEvent::LayoutHintQEvent::LayoutRequest
QEvent::ReparentQEvent::ParentChange
QFileInfo::ExeGroupQFile::ExeGroup
QFileInfo::ExeOtherQFile::ExeOther
QFileInfo::ExeOwnerQFile::ExeOwner
QFileInfo::ExeUserQFile::ExeUser
QFileInfo::ReadGroupQFile::ReadGroup
QFileInfo::ReadOtherQFile::ReadOther
QFileInfo::ReadOwnerQFile::ReadOwner
QFileInfo::ReadUserQFile::ReadUser
QFileInfo::WriteGroupQFile::WriteGroup
QFileInfo::WriteOtherQFile::WriteOther
QFileInfo::WriteOwnerQFile::WriteOwner
QFileInfo::WriteUserQFile::WriteUser
QFrame::GroupBoxPanelQFrame::StyledPanel
QFrame::LineEditPanelQFrame::StyledPanel
QFrame::MenuBarPanelQFrame::StyledPanel
QFrame::PopupPanelQFrame::StyledPanel
QFrame::TabWidgetPanelQFrame::StyledPanel
QFrame::ToolBarPanelQFrame::StyledPanel
QImage::ScaleFreeQt::IgnoreAspectRatio
QImage::ScaleMaxQt::KeepAspectRatioByExpanding
QImage::ScaleMinQt::KeepAspectRatio
Qt::IdenticalQKeySequence::ExactMatch
Qt::NoMatchQKeySequence::NoMatch
Qt::PartialMatchQKeySequence::PartialMatch
QLayout::AutoQLayout::SetDefaultConstraint
QLayout::FixedQLayout::SetFixedSize
QLayout::FreeResizeQLayout::SetNoConstraint
QLayout::MinimumQLayout::SetMinimumSize
QMacStyle::SizeNoneQMacStyle::SizeDefault
QSettings::GlobalQSettings::SystemScope
QSettings::UserQSettings::UserScope
QSize::ScaleFreeQt::IgnoreAspectRatio
QSize::ScaleMaxQt::KeepAspectRatioByExpanding
QSize::ScaleMinQt::KeepAspectRatio
QSizePolicy::HorizontalQSizePolicy::Horizontally
QSizePolicy::VerticalQSizePolicy::Vertically
QSlider::AboveQSlider::TicksAbove
QSlider::BelowQSlider::TicksBelow
QSlider::BothQSlider::TicksBothSides
QSlider::LeftQSlider::TicksLeft
QSlider::NoMarksQSlider::NoTicks
QSlider::RightQSlider::TicksRight
QSocket::ClosingQ3Socket::Closing
QSocket::ConnectedQ3Socket::Connected
QSocket::ConnectingQ3Socket::Connecting
QSocket::ConnectionQ3Socket::Connection
QSocket::ErrConnectionRefusedQ3Socket::ErrConnectionRefused
QSocket::ErrHostNotFoundQ3Socket::ErrHostNotFound
QSocket::ErrSocketReadQ3Socket::ErrSocketRead
QSocket::HostLookupQAbstractSocket::HostLookupState
QSocket::IdleQAbstractSocket::UnconnectedState
QSqlError::ConnectionQSqlError::ConnectionError
QSqlError::NoneQSqlError::NoError
QSqlError::StatementQSqlError::StatementError
QSqlError::TransactionQSqlError::TransactionError
QSqlError::UnknownQSqlError::UnknownError
QStyle::CC_ListViewQStyle::CC_Q3ListView
QStyle::SH_UnderlineAcceleratorQStyle::SH_UnderlineShortcut
QStyle::Style_ActiveQStyle::State_Active
QStyle::Style_AutoRaiseQStyle::State_AutoRaise
QStyle::Style_BottomQStyle::State_Bottom
QStyle::Style_ChildrenQStyle::State_Children
QStyle::Style_DefaultQStyle::State_None
QStyle::Style_DownQStyle::State_DownArrow
QStyle::Style_EditingQStyle::State_Editing
QStyle::Style_EnabledQStyle::State_Enabled
QStyle::Style_FocusAtBorderQStyle::State_FocusAtBorder
QStyle::Style_HasFocusQStyle::State_HasFocus
QStyle::Style_HorizontalQStyle::State_Horizontal
QStyle::Style_ItemQStyle::State_Item
QStyle::Style_MouseOverQStyle::State_MouseOver
QStyle::Style_NoChangeQStyle::State_NoChange
QStyle::Style_NoneQStyle::State_None
QStyle::Style_OffQStyle::State_Off
QStyle::Style_OnQStyle::State_On
QStyle::Style_OpenQStyle::State_Open
QStyle::Style_RaisedQStyle::State_Raised
QStyle::Style_RectangleQStyle::State_Rectangle
QStyle::Style_SelectedQStyle::State_Selected
QStyle::Style_SiblingQStyle::State_Sibling
QStyle::Style_SunkenQStyle::State_Sunken
QStyle::Style_TopQStyle::State_Top
QStyle::Style_UpQStyle::State_Up
QTabBar::RoundedAboveQTabBar::RoundedNorth
QTabBar::RoundedBelowQTabBar:: RoundedSouth
QTabBar::TriangularAboveQTabBar:: TriangularNorth
QTabBar::TriangularBelowQTabBar:: TriangularSouth
QTextEdit::MovePgDownQTextEdit::MovePageDown
QTextEdit::MovePgUpQTextEdit::MovePageUp
QToolButton::RightQToolButton::BesideIcon
QToolButton::UnderQToolButton::BelowIcon
QValidator::ValidQValidator::Intermediate
QVariant::IconSetQCoreVariant::Icon
QWidget::ClickFocusQt::ClickFocus
QWidget::NoFocusQt::NoFocus
QWidget::StrongFocusQt::StrongFocus
QWidget::TabFocusQt::TabFocus
QWidget::WheelFocusQt::WheelFocus
Qt::AlignAutoQt::AlignLeft
Qt::AltButtonQt::AltModifier
Qt::AscendingQt::AscendingOrder
Qt::BottomQt::DockBottom
Qt::BottomLeftQt::BottomLeftCorner
Qt::BottomRightQt::BottomRightCorner
Qt::BreakAnywhereQt::TextWrapAnywhere
Qt::ControlButtonQt::ControlModifier
Qt::CustomPatternQt::TexturePattern
Qt::DescendingQt::DescendingOrder
Qt::DontClipQt::TextDontClip
Qt::DontPrintQt::TextDontPrint
Qt::ExpandTabsQt::TextExpandTabs
Qt::IncludeTrailingSpacesQt::TextIncludeTrailingSpaces
Qt::KeyButtonMaskQt::KeyboardModifierMask
Qt::Key_BackSpaceQt::Key_Backspace
Qt::Key_BackTabQt::Key_Backtab
Qt::Key_MediaPrevQt::Key_MediaPrevious
Qt::Key_NextQt::Key_PageDown
Qt::Key_PriorQt::Key_PageUp
Qt::Key_aacuteQt::Key_Aacute
Qt::Key_acircumflexQt::Key_Acircumflex
Qt::Key_adiaeresisQt::Key_Adiaeresis
Qt::Key_aeQt::Key_AE
Qt::Key_agraveQt::Key_Agrave
Qt::Key_aringQt::Key_Aring
Qt::Key_atildeQt::Key_Atilde
Qt::Key_ccedillaQt::Key_Ccedilla
Qt::Key_eacuteQt::Key_Eacute
Qt::Key_ecircumflexQt::Key_Ecircumflex
Qt::Key_ediaeresisQt::Key_Ediaeresis
Qt::Key_egraveQt::Key_Egrave
Qt::Key_ethQt::Key_ETH
Qt::Key_iacuteQt::Key_Iacute
Qt::Key_icircumflexQt::Key_Icircumflex
Qt::Key_idiaeresisQt::Key_Idiaeresis
Qt::Key_igraveQt::Key_Igrave
Qt::Key_ntildeQt::Key_Ntilde
Qt::Key_oacuteQt::Key_Oacute
Qt::Key_ocircumflexQt::Key_Ocircumflex
Qt::Key_odiaeresisQt::Key_Odiaeresis
Qt::Key_ograveQt::Key_Ograve
Qt::Key_oslashQt::Key_Ooblique
Qt::Key_otildeQt::Key_Otilde
Qt::Key_thornQt::Key_THORN
Qt::Key_uacuteQt::Key_Uacute
Qt::Key_ucircumflexQt::Key_Ucircumflex
Qt::Key_udiaeresisQt::Key_Udiaeresis
Qt::Key_ugraveQt::Key_Ugrave
Qt::Key_yacuteQt::Key_Yacute
Qt::KeypadQt::KeypadModifier
Qt::LeftQt::DockLeft
Qt::MV_10_DOT_0QSysInfo::MV_10_0
Qt::MV_10_DOT_1QSysInfo::MV_10_1
Qt::MV_10_DOT_2QSysInfo::MV_10_2
Qt::MV_10_DOT_3QSysInfo::MV_10_3
Qt::MV_10_DOT_4QSysInfo::MV_10_4
Qt::MV_9QSysInfo::MV_9
Qt::MV_CHEETAHQSysInfo::MV_10_0
Qt::MV_JAGUARQSysInfo::MV_10_2
Qt::MV_PANTHERQSysInfo::MV_10_3
Qt::MV_PUMAQSysInfo::MV_10_1
Qt::MV_TIGERQSysInfo::MV_10_4
Qt::MV_UnknownQSysInfo::MV_Unknown
Qt::MetaButtonQt::MetaModifier
Qt::MinimizedQt::DockMinimized
Qt::NoAccelQt::TextHideMnemonic
Qt::OverlineQt::TextOverline
Qt::RightQt::DockRight
Qt::ShiftButtonQt::ShiftModifier
Qt::ShowPrefixQt::TextShowMnemonic
Qt::SingleLineQt::TextSingleLine
Qt::StrikeOutQt::TextStrikeOut
Qt::TopQt::DockTop
Qt::TopLeftQt::TopLeftCorner
Qt::TopRightQt::TopRightCorner
Qt::TornOffQt::DockTornOff
Qt::UnderlineQt::TextUnderline
Qt::UnmanagedQt::DockUnmanaged
Qt::WNorthWestGravityQt::WStaticContents
Qt::WRepaintNoEraseQt::WNoAutoErase
Qt::WStyle_DialogQt::WType_Dialog
Qt::WStyle_NoBorderExQt::WStyle_NoBorder
Qt::WType_Modal(Qt::WType_Dialog | Qt::WShowModal)
Qt::WV_2000QSysInfo::WV_2000
Qt::WV_2003QSysInfo::WV_2003
Qt::WV_32sQSysInfo::WV_32s
Qt::WV_95QSysInfo::WV_95
Qt::WV_98QSysInfo::WV_98
Qt::WV_CEQSysInfo::WV_CE
Qt::WV_CENETQSysInfo::WV_CENET
Qt::WV_CE_basedQSysInfo::WV_CE_based
Qt::WV_DOS_basedQSysInfo::WV_DOS_based
Qt::WV_MeQSysInfo::WV_Me
Qt::WV_NTQSysInfo::WV_NT
Qt::WV_NT_basedQSysInfo::WV_NT_based
Qt::WV_XPQSysInfo::WV_XP
Qt::WordBreakQt::TextWordWrap
Qt::IbeamCursorQt::IBeamCursor

In addition, the following window flags have been either replaced with widget attributes or have been deprecated:

Qt 3 typeQt 4 equivalent
Qt::WDestructiveCloseUse QWidget::setAttribute(Qt::WA_DeleteOnClose) instead.
Qt::WStaticContentsUse QWidget::setAttribute(Qt::WA_StaticContents) instead.
Qt::WNorthWestGravity
Qt::WNoAutoEraseUse QWidget::setAttribute(Qt::WA_NoBackground) instead.
Qt::WResizeNoErase
Qt::WRepaintNoErase
Qt::WPaintCleverUnnecessary in Qt 4.
Qt::WMacNoSheetUnnecessary 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 typeQt 4 equivalent
Qt::WShowModalUse QWidget::setWindowModality(Qt::ApplicationModal) instead.
Qt::WGroupLeaderUse QWidget::setWindowModality(Qt::WindowModal) for each child dialog of the group leader, but do not change the modality of the group leader itself.

Properties

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 nameQt 4 name
QButton::accelQButton::shortcut
QButton::onQButton::checked
QButton::toggleButtonQAbstractButton::checkable
QDial::lineStepQDial::singleStep
QDial::maxValueQDial::maximum
QDial::minValueQDial::minimum
QDialog::modalQDialog::isModal
QLineEdit::editedQLineEdit::modified
QLineEdit::hasMarkedTextQLineEdit::hasSelectedText
QLineEdit::markedTextQLineEdit::selectedText
QObject::nameQObject::objectName
QProgressDialog::progressQProgressDialog::value
QProgressDialog::totalStepsQProgressDialog::maximum
QProgressDialog::wasCancelledQProgressDialog::wasCanceled
QPushButton::iconSetQPushButton::icon
QScrollBar::draggingSliderQScrollBar::sliderDown
QScrollBar::lineStepQScrollBar::singleStep
QScrollBar::maxValueQScrollBar::maximum
QScrollBar::minValueQScrollBar::minimum
QSlider::lineStepQSlider::singleStep
QSlider::maxValueQSlider::maximum
QSlider::minValueQSlider::minimum
QSpinBox::lineStepQSpinBox::singleStep
QSpinBox::maxValueQSpinBox::maximum
QSpinBox::minValueQSpinBox::minimum
QTabBar::currentTabQTabBar::currentIndex
QTabWidget::currentPageQTabWidget::currentWidget
QToolButton::iconSetQToolButton::icon
QToolButton::textLabelQToolButton::text
QWidget::captionQWidget::windowTitle
QWidget::iconQWidget::windowIcon
QWidget::iconTextQWidget::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 propertyQt 4 read functionQt 4 write function
QSqlDatabase::connectOptionsQSqlDatabase::connectOptions()QSqlDatabase::setConnectOptions()
QSqlDatabase::databaseNameQSqlDatabase::databaseName()QSqlDatabase::setDatabaseName()
QSqlDatabase::hostNameQSqlDatabase::hostName()QSqlDatabase::setHostName()
QSqlDatabase::passwordQSqlDatabase::password()QSqlDatabase::setPassword()
QSqlDatabase::portQSqlDatabase::port()QSqlDatabase::setPort()
QSqlDatabase::userNameQSqlDatabase::userName()QSqlDatabase::setUserName()

Some properties have been removed from Qt 4, but the associated access functions are provided if QT3_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 the Qt3Support 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 propertyQt 4 read function (QT3_SUPPORT)Qt 4 write function (QT3_SUPPORT)
QMenuBar::separatorQMenuBar::separator()QMenuBar::setSeparator()
QPushButton::menuButtonQPushButton::isMenuButton()N/A
QTabWidget::marginQTabWidget::margin()QTabWidget::setMargin()
QTextEdit::textFormatQTextEdit::textFormat()QTextEdit::setTextFormat()
QWidget::backgroundBrushQWidget::backgroundBrush()N/A
QWidget::backgroundModeQWidget::backgroundMode()QWidget::setBackgroundMode()
QWidget::backgroundOriginQWidget::backgroundOrigin()QWidget::setBackgroundOrigin()
QWidget::colorGroupQWidget::colorGroup()QWidget::setColorGroup()
QWidget::customWhatsThisQWidget::customWhatsThis()QWidget::setCustomWhatsT