Porting Qt 3 to Qt 4 Issues: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
m (Wieland moved page PortingQt3ToQt4 to Porting Qt 3 to Qt 4 Issues: better title)
(Simplify punctuation)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
{{LangSwitch}}
 
[[Category:HowTo]]
[[Category:HowTo]]
 
This page is intended to describe porting issues not mentioned in the official porting documentation.
= Qt3 to Qt4 porting issues =
 
This page is intended to describe porting issues not mentioned in the [http://qt.nokia.com/doc/porting4.html official porting documentation.]


== clearWState( WState_Polished ) ==
== clearWState( WState_Polished ) ==
Line 15: Line 11:
== Layout Names not Saved ==
== 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.
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:
The simplest solution is to:
''' create QLayout* members in the class with names of former layouts
* 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.
* 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.


Line 33: Line 29:
<code>
<code>
const QObjectList *list = obj->children();
const QObjectList *list = obj->children();
QObjectListIterator it('''list);
QObjectListIterator it(*list);
for (it.toFirst();it.current(); ++it){
for (it.toFirst();it.current(); ++it) {
QObject''' o = it.current();
    QObject''' o = it.current();
   
}
}
</code>
</code>
Line 44: Line 40:
<code>
<code>
foreach (QObject* o, obj->children()) {
foreach (QObject* o, obj->children()) {
   
}
}
</code>
</code>
Line 55: Line 51:
Also, some flags (IO_Sequential) now cannot be set without sub-classing, only checked.
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.
Search the porting page for QIODevice for the flag itself, for example IO_Sequential.


== QTranslatorMessage ==
== QTranslatorMessage ==
Line 65: Line 61:
* reimplement application logic to avoid usage of QTranslatorMessage
* reimplement application logic to avoid usage of QTranslatorMessage


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


== QApplication::eventLoop() ==
== QApplication::eventLoop() ==
Line 74: Line 70:
== QLabel::setAutoResize() ==
== 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.
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:
The suggested replacements are:
Line 110: Line 106:
=== Q3Action can be added to QMenu, but causes crash in destruction. ===
=== 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
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.io/browse/QTBUG-11306


=== Tear-off menus ===
=== Tear-off menus ===

Latest revision as of 13:22, 23 August 2015

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

This page is intended to describe porting issues not mentioned in the official porting documentation.

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

const QObjectList *list = obj->children();
QObjectListIterator it(*list);
for (it.toFirst();it.current(); ++it) {
    QObject''' o = it.current();
    
}

may be replaced with

foreach (QObject* o, obj->children()) {
    
}

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 for 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.io/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

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()

QRegExp re; bool res = re.match(s);<code>

may be replaced with

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.io/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.