Qt3 to Qt4 porting issues

This page is intended to describe porting issues not mentioned in the official porting documentation. [qt.nokia.com]

clearWState( WState_Polished )

This function is internal in Qt3. But it is called from Designer-generated files. Maybe, Qt developers think that Designer-generated files will be updated (re-generated) during the porting process, so, this function is not documented.

May be removed in the ported code.

Layout Names not Saved

If uic3 is used for source file generation from *.ui files then layout names are not saved. Even object “name” of layout is not used in generated code.

The simplest solution is to:

  • create QLayout* members in the class with names of former layouts
  • in the constructor assign to them the pointers to the automatically generated layouts. Search the XML structure of the *.ui file to find correspondent object.

QApplication::wakeUpGUIThread()

Still no answer how to replace.

QObjectListIterator

QObjectListIterator class does not exist any more.

The old code

  1. const QObjectList *list = obj->children();
  2. QObjectListIterator it(*list);
  3. for (it.toFirst();it.current(); ++it){
  4.     QObject* o = it.current();
  5.     ...
  6. }

may be replaced with

  1. foreach (QObject* o, obj->children()) {
  2.     ...
  3. }

QIODevice::setFlags()

Qt doc mentions that “the IO_xxx flags have been revised, and the protected setFlags() function removed”.

But search for setFlags() in the documentation using Qt Assistant does not return that page.
Also, some flags (IO_Sequential) now cannot be set without sub-classing, only checked.

Search the porting page http://doc.qt.nokia.com/4.7/porting4.html#QIODevice for the flag itself, for example IO_Sequential.

QTranslatorMessage

QTranslatorMessage is removed in Qt4.

Possible solutions:

  • port from QLinguist
  • reimplement application logic to avoid usage of QTranslatorMessage

See http://bugreports.qt.nokia.com/browse/QTBUG-1449

QApplication::eventLoop()

Function is removed in Qt4.
Still no answer how to replace.

QLabel::setAutoResize()

In Qt4 the function QLabel::setAutoResize() disappeared. The porting documentation says that this virtual function is replaced with “Setter”, but no setter provided.

The suggested replacements are:

  • adjustSize()
  • to determine the size of the text and call setFixedSize() on the label

But both of them requires the additional connection (connect to textChanged() signal and update label size).

Also you can put label in layout and set size policy.

Custom QToolTip

QToolTip no longer supports inheritance. To customize tooltip behavior on widgets, intercept QHelpEvents in the widget’s event() function. How to article [developer.qt.nokia.com]

Custom drawing for QPushButton

QPushButton no longer has a drawButton and drawButtonLabel virtual methods for custom painting. Painting in those methods should be moved to the paintEvent handler.

QRegExp::match()

  1. QRegExp re; bool res = re.match(s);

may be replaced with

  1. QRegExp re; bool res = re.indexIn(s, 0) != -1;

Run-time Issues

Transparent Widgets

Suppose that the editor widget is created in the Table or Tree cell. If editor is a complex widget with children (for example entry field on the left followed by text label with measurement units followed by the button to reset to default value) then it background may be transparent. In this case you will see original contents of the cell under the editor widget.

To avoid this use setAutoFillBackground() function for the editor widget.

Q3Action can be added to QMenu, but causes crash in destruction.

While porting actions and menus, it is easy to make the mistake of having a Q3Action call addTo(widget) where widget is a QMenu. See http://bugreports.qt.nokia.com/browse/QTBUG-11306

Tear-off menus

Handling of tear-off menus may need to be adjusted. In Qt3, a tear-off menu has an item for the tear-off action. Although Qt3Support provides insertTearOffHandle(), in Qt 4 this simply sets the tearOffEnabled property of QMenu. A tear-off item is not put in the menu. If code adjusted indices of the menu items for the tear-off item, they must now be rewritten to account for the fact that the item is no longer there.

QToolBar Caption and Close Button

QToolBar in the floating state has no window caption and “close” (“x”) button.

No info about restoring the Qt3 look of toolbar.

QLineEdit focus policy

If a QLineEdit focus policy has been set to NoFocus, it will not process key events even if grabKeyboard() is called. Previously the QLineEdit would still process the key events. Now, the focus must be set to the QLineEdit in order for key events to be processed.

Polishing widget

Widgets implementing the polish virtual slot must be converted to look for QEvent::Polish events in the event() handler.

Categories: