: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/usieve/stoopidsimple.com/includes/common.inc on line 1782.
: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/usieve/stoopidsimple.com/includes/common.inc on line 1782.
Qt 3->4 Porting | stoopidsimple.com

Qt 3->4 Porting

salem | 2005-09-05 19:59

I finally got arround to working on Tonality. I ported it to Qt 4.0 this weekend. I hope this article helps others decide how to handle their Qt porting.

So first the good news. If you don't mind compiling with the Qt3 legacy support libs, then the transition is rather painless. Trolltech provides a good guide and tools for this conversion. In tonality the only problems that needed manual intervention were related to the return value semantics of QDir/QFileInfo routines (new list iterator semantics).

However, I decided I wanted tonality to be Qt4 clean, without requiring Qt3 legacy support. So... I turn off QT += qt3support and starting hacking at the compilation errors. This was a totally different experience. It was painful and slow and by the time I finished it I was sure that Trolltech had changed some things just to piss me off :) The nice table based documentation that they provide for the automated Qt3=>4 translation is not provided for the full on differences between Qt3 and Qt4.

However, in the end, the only thing that I could not find a solution for was QSplitter::KeepSize. I tried the new Stretch settings but, I cound not replace the functionality of QSplitter::KeepSize.

Here is my list of differences that I had to resolve to compile without qt3support (note that the porting guide did not help with these issues):

QWidget no longer has a name field. All of your constructors of classes which inherit QWidget need to be updated.

QDir->absPath changed to absolutePath()

QRegExp Constructor changed, case sensitivity is no longer a bool, it is now an enum. Qt::CaseSensitive/Qt::CaseInsensitive

QStatusBar->message() was renamed showMessage()

QMenu->insertItem() changed to addAction(). This also means that if you want to set menu entry names, you must now get the return value of addAction().

QPixmap( const QImage & ) doesn't exist, now use:
static public: QPublic::fromImage( QPixmap ... );

QWidget->isShown() renamed to isVisible()

QMainWidget::setCaption() does not exist. Use QWidget::setWindowTItle()

QImage::reset() is gone, just assign to QImage()?

QPixmap::convertFromImage() is gone use:

QPixmap p(QPixmap::fromImage( QImage ));

QString::findRev() is gone, use: QString::lastIndexOf()

QFileDialog::getSaveFileName() now takes a QWidget as first argument.

Nested layouts are can no longer be done with widget parent/child relationship. E.g. QHBoxLayout cannot take another layout as a parent. You must now use "addLayout()". Ex:

QLayout *parent = new QHboxLayout(widget);
QLayout *child  = new QVboxLayout(widget);

QToolTip::add is gone. Now use QWidget->setToolTip()

QWidget->setPaletteForegroundColor() is gone, you must now do:

QPalette p;
QWidget->setPalette( QPalette )

QMenuBar::addMenu() does not accept a string and a menu. If you create the menu before the entry is added then you must get the return value from addMenu() and then setText():

QAction *a  = menuBar()->addMenu(fileMenu);

No QVGroupBox, use QGroupBox. Note: I did not find a replacement for QHGroupBox.



User login