Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
This document describes porting applications from Qt 3.x to Qt 4.x.
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.x.
The Qt 4.x series is not binary compatible with the 3.x series. This means programs compiled for Qt 3.x must be recompiled to work with Qt 4.x. Qt 4.x is also not completely source compatible with 3.x, however all points of incompatibility cause compiler errors or run-time messages (rather than mysterious results). Qt 4.x includes many additional features and discards obsolete functionality. Porting from Qt 3.x to Qt 4.x is straightforward, and once completed makes the considerable additional power and flexibility of Qt 4.x available for use in your applications.
To port code from Qt 3.x to Qt 4.x:
Table of contents:
The following functions are obsolete. Most will continue to work in COMPAT mode, but we recommend not using them in new code.
Widget background painting has been greatly improved, supporting flickerfree updates and making it possible to have half transparent widgets. This renders the following background handling functions obsolete:
A widget now receives change events in its QWidget::changeEvent() handler. This makes the following virtual change handlers obsolete:
The following functions were slots, but are no more:
The following functions were incorrectly marked as virtual:
The following functions are obsolete. Most will continue to work in COMPAT mode, but we recommend not using them in new code.
If you specify a negative value for len to left() or right() then an empty string is returned.
The QString constructor that takes a QByteArray no longer considers a 0 as the end of the string, but rather includes all 0 into the string. The resulting string has always the length of the byte array.
Virtuals readBlock and writeBlock now accept a Q_LONG length argument (rather than a Q_ULONG). All subclass will need to change as this is a pure virtual function build errors will occur.
QByteArray is now implicitly shared. It provides most of the functionality QCString used to provide and is favored over the deprecated QCString.
* case sensitive find() has been removed. Use QString instead (with QString::indexOf()).
QCString is deprecated. QByteArray should do everything you need from an 8-bit string class. For text handling use QString instead.
The class is now implicitly shared.
Removed methods:
Changed methods:
QStringList now inherits from QList<QString> and can no longer be converted to a QValueList<QString>. Since QValueList inherits QList a cast will work as expected.
This change implies some API incompatibilities for QStringList:
QValueList now inherits from QList, but is kept source compatible to the Qt3 class.
QList<Type>::Iterators become invalid on modifying the list (functions like append(), prepend()), use index based access instead when modifying the list.
children() and QueryList now return a QObjectList instead of a pointer to a QObjectList. See also the comments on QObjectList.
killTimers() has been removed.
QObjectList is a typdef to a QList of QObject pointers (it was a QPtrList in Qt3).
QPointArray is now implicitly shared and is based on QVector. The return type for the setPoints() and putPoints() functions is now void instead of bool. isNull() is obsolete; use isEmpty() instead. copy() is obsolete, use standard assignment instead.
Has been removed.
QWidgetList is a typdef to a QList of QWidget pointers (it was a QPtrList in Qt3).
Both allWidgets() and topLevelWidgets() return a QWidgetList (it was a pointer to a QWidgetList in Qt3). This resolves some memory management issues using these methods.
QColorGroup has been removed, its API has been merged into QPalette. You should now use a QPalette to implement all things that were used by QColorGroup. A default QPalette is no longer all-black, but uses the application palette.
QRects are now exclusive. This means that
x + width == right y + height == bottom
In Qt 3.x this was: x + width - 1 == right y + height - 1 == bottom
QRect(QPoint(0, 0), QSize(10, 10)) or QRect(0, 0, 10, 10) -> width() == height() == 10, would be 10 in Qt 3.x -> bottom() == right() == 10, would be 9 in Qt 3.x
QRect(QPoint(0, 0), QPoint(10, 10)) -> width() == height() == 10, would be 11 in Qt 3.x -> bottom() == right() == 10, would be 10 in Qt 3.x
Null QRegions have been removed, use isEmpty() in most places where you would have used a null Qregion. rects() now returns a QVector<QRect> instead of QMemArray<QRect>.
QIconFactory has been removed in favor of using function pointers. Generally this involves taking the QIconFactory::createPixmap() function and making it a regular functions. Use QIconSet::setPixmapGeneratorFn() in place of QIconSet::installFactory() and QIconSet::setDefaultPixmapGeneratorFn() and QIconSet::defaultPixmapGeneratorFn() in place of QIconFactory::installDefaultFactory() and QIconFactory::defaultFactory() respectively.
These classes have been removed use QHash<type *, T*> QHash<int, T*>, and QHash<QString, T*> respecitively. Please note that while the dictionary classes allowed for multiple entries with the same key, the current QHash implementation only allows this if insertMulti() is used to insert elements.
Note about QDict->QHash conversion: QDict has one []-operator which is const, but QHash has two. The non-const [] operator for QHash creates a default value if there is no pair that matches the passed key. So a = b[c]; will create an element if called in a non-const environment. Rather than [], use value(), which returns a default constructed value (or 0 for pointers) but does not insert it into the container.
Note that there are two types of iterators for QHash, both STL-style and Qt-style. STL-style iterators are recommended for internal use, as these are more efficient.
QPtrDict has been removed, please use QHash<type *, T *> instead. If you previously assigned a value with find use value() in this case instead, it will keep the same semantics (that it returns 0 if it can't find the pointer).
The following functions are obsolete. Most will continue to work in COMPAT mode, but we recommend not using them in new code.
QDir::encodedEntryList has been removed.
fileInfoList() and drives() now return a QList<QFileInfo> and not a QPtrList<QFileInfo> *. Code using these methods will have to be adapted.
Both classes no longer subclass from QNetworkProtocol. They only provide the direct interface to FTP and HTTP.
The functions sliderStart() and sliderRect() have been removed. You can retrieve this functionality with QAbstractSlider::sliderPosition() and QStyle::querySubControlMetrics() respectively.
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 function QPaintDevice::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 and drawPixmap instead.
Probably something needs to be said about new stuff from painting? Don't know, I didn't do that part.
QPicture::copy() is deprecated and QPicture::detach() is now a public internal function. In general, one should have never needed to call these functions.
page setup / print setup -> Use QPrintDialog, QPageSetupDialog Compat functions: margins Killed -> setMargins
QSqlRecord behaves like a vector now, QSqlRecord::insert() will actually insert a new field instead of replacing the existing one.
QSqlDatabase is now a smart pointer that is passed around by value. Simply replace all QSqlDatabase pointer by QSqlDatabase objects.
QSqlQuery::prev() was renamed to QSqlQuery::previous(). There is a function call for compatibility, but if you subclassed QSqlQuery, you have to reimplement previous() instead of prev().
The enum Type was renamed to ErrorType, The values were renamed as well:
The function setResizeMode() has been moved into compat. Set the stretch factor in the widget's size policy to get equivalent functionality.
The obsolete function drawSplitter() has been removed. Use QStyle::drawPrimitive() to acheive similar functionality.
Copyright © 2004 Trolltech. | Trademarks | Qt 4.0.0-tp1 |