[bt-devel] My QT experience

Robert Hunt Robert_Hunt at sil.org
Thu Aug 18 06:28:51 MST 2005


Philippines.

    I worked as a software engineer a couple of decades ago, moving from 
assembly language to PL/M to C to C++ from embedded to MS-DOS to Windows 
to MS-Visual Studio. I have done a little bit of programming since then 
-- a few small work projects and some hobby stuff.

    Last year I started with Gentoo Linux and I have really enjoyed all 
the learning that has involved in the switch from Windows. I still see 
lots of room for improvement in the system, but on the other hand, the 
range and quality of free(x2) software available is extremely 
impressive. I love Firefox and I tolerate Thunderbird. I tolerate Gaim 
but I do enjoy the Festival speech synthesis plug-in. I still don't have 
anywhere the functionality on my Toshiba A70 laptop that Windows gives 
(e.g., even "system restart" shuts down the OS but locks up without 
rebooting) but I tolerate that (and might not buy a Toshiba next time).

     I wanted to learn a little about programming in Linux so dabbled 
with wxWindows/wxWidgets, Python and wxPython and Mono/C#, etc. (I keep 
away from Java) but when I heard that QT4 was going to have an 
OpenSource version I decided to go for that. Meanwhile, while I was 
waiting, I went ahead and converted a small MFC program to QT3.

    I found that converting from MFC to QT involved two main issues:
1/ Converting CString and a lot of container classes. (I was using 
CString and CPtrArray<> etc. quite heavily.)
2/ Converting the GUI/OS stuff.

    On the container classes, I decided to go to STL so that if I ever 
converted to another class library, I wouldn't have to do all these 
conversions again (as long as I stuck with C++). After using MFC, I 
didn't find the STL calls intuitive (e.g. 'push_back' instead of 
'append') but it seemed to be relatively straightforward even if tedious.

    I converted CString to QString and there were a lot of changes like 
length() went to size() if I remember correctly and there were different 
philosophies on case so IsEmpty() went to isEmpty() etc. but they were 
pretty straightforward to substitute. Many of the string manipulation 
functions didn't have exact equivalents but it didn't take too long to 
work out the QT way of doing it. It took me a while to work around 
QString[] returning a QCharRef rather than a char but I finally figured 
that out.

    The OS stuff such as file IO wasn't quite so straightforward  but 
not too bad either. QTAssistant was great and I had all of the class 
information and sample code at my fingertips even when away from the 
Internet. In fact, in terms of help, it was much better than the MFC 
help system where many of my queries returned results about other MS 
products that I wasn't using (even though I had the filter set to C++/MFC).

    The GUI stuff was fun and signals and slots seemed very easy to use. 
Some of the autolayout stuff was very different from the MFC approach I 
had come from, but it was very quick to try out.

    All in all I really enjoyed learning QT3 and found it quite clean 
and intuitive -- more so than MFC which always felt like a hack (which 
it was). I found the debugging support in KDevelop/gdb not nearly as 
good as I was used to in Visual Studio and I haven't figured out how to 
use Valgrind yet.

    The shock came when QT4 came out and I converted to that. I had read 
the advance notices so I was aware of some of the planned changes in 
general terms. I decided not to try any automatic conversion tools as 
this was a learning experience for me so like the conversion from MFC, I 
was doing it all by hand. What stunned me is that the paradigm for QT4 
is quite different from QT3 in many ways.

    The container classes I had converted to STL so no problems/changes 
there. QStrings changed quite a bit and I ended up completely removing 
any leftover 'char's from my program (still leftover from MFC days) and 
using QChar everywhere instead (also 'char*' to QString&). This was 
quite a bit of work, but the benefit was that my code is much more 
Unicode compliant so I have no complaints there. The QString class is 
certainly very versatile. I get the impression that the Unicode and 
localization/translation support in QT4 is excellent.

    The size() methods for most classes now return an int instead of a 
uint so I went from int in MFC to uint in QT3 (which seemed more logical 
to me) back to int in QT4.

    But a lot of the GUI stuff changed very dramatically. Some classes 
disappeared completely, e.g., QHBox and QVBox. Ah yes, there's still 
compatibility versions (called Q3HBox and Q3VBox but I wasn't messing 
with compatibility stuff that will disappear again one day). And many 
things changed in their philosophy, e.g.,

    m_pHistoryBoxLabel = *new* QLabel( "&History", m_pMain, "HistoryBoxLabel" );  // if I've remembered it correctly

became

    m_pHistoryBoxLabel = *new* QLabel();
    m_pHistoryBoxLabel->setText( "&History ");
    m_pMain->addWidget( m_pHistoryBoxLabel );

and
/    m_pRepeatAction->addTo( m_pToolBar );/
became

    m_pToolBar->addAction( m_pRepeatAction );

so you can see that there's quite a bit of editing involved. In fact, I 
found the conversion from QT3 to QT4 more frustrating than the 
conversion from MFC to QT3. If I had realized that the changes were 
going to be so wide reaching, I wouldn't have bothered making the 
intermediate step to QT3.

    Some things are not working the way that it seemed they should. In 
particular, my program crashes when working with toolbars and status bar 
panes from the code. My code for that is all commented out for now. I've 
found several places where the documentation is lacking, and one or two 
where it is plain wrong. I guess that's what you get for using a version 
x.0.0 and hopefully it'll be improved/fixed in V4.0.1 or something.

    Some things I still haven't worked out how to do yet. For instance 
QTextEdit had a signal clicked(int,int) that I conveniently used in QT3 
but I can't find any way to get a signal if a QTextEdit is clicked on in 
QT4. QT3 had a setPaletteBackgroundColor(QColor) for QWidget and QT4 has 
much more complex (but more powerful) painting controls but I haven't 
figured them out yet so my application is back to black and white for now.

    So basically I want to say DON'T UNDERESTIMATE THE WORK TO PORT FROM 
QT3 to QT4, especially if you don't want to use the porting tool and the 
compatibility layer (and I didn't try that as I said). The changes are 
both major and widespread. I'm sure QT4 is cleaner and more powerful, 
but that makes it very different to use from QT3!

    I'm sure QT4 is going to be a great product, and the open source 
licensing on all supported platforms makes it a true contender now for 
cross-platform open-source programming. But then I guess it'll take a 
few QT update releases from TrollTech and then a few Linux releases 
after that before QT4 libraries start becoming standard around the place.

    It was an interesting learning experience. Maybe I'll have another 
look at Mono next...

Robert.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.crosswire.org/pipermail/bt-devel/attachments/20050818/bfb6a08e/attachment.html


More information about the bt-devel mailing list