![]() |
ホーム · All Namespaces · 全てのクラス · メインのクラス · グループ別 · Modules · 関数一覧 |
[Previous: Porting Guides] [Contents] [Next: Porting to Qt 4 - Virtual Functions]
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 へ移植する:
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:
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 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_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 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 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 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 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.
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 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 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::setCustomWhatsT |