Slashdot Mirror


C++ GUI Programming with Qt 3

Alex Moskalyuk writes "Before Sun monopolized the notion of 'write once, run everywhere,' those who enjoy programming in C++ had the choice of using Qt libraries that provide cross-platform GUI support. C++ GUI Programming with Qt3 is written by the employees of TrollTech, the company that created and currently distributes the Qt environment." Read on for the rest of Alex's review. C++ GUI Programming with Qt 3 author Jasmin Blanchette, Mark Summerfield pages 464 publisher Prentice Hall PTR rating 9 reviewer Alex Moskalyuk ISBN 0131240722 summary Practical introduction into GUI programming with Qt

The first question that came to mind when I got this book - is there any need for it? Qt's Documentation is detailed and extensive with how-to's and an API reference available online for free. I have done GUI development in .NET (with C#) and Tk (with Perl) environments, and even though I've never tried Qt, the site with tutorials looked like a sufficiently good resource to start.

However, after getting through the first few chapters, religiously trying out the code, my opinions on whether a separate book is needed have changed. Jasmin Blanchette and Mark Summerfield's book can take a sufficiently clueless newbie with some C++ knowledge and guide him through the intricacies of GUI building, providing practical advice and some bits of experience on the way. You learn about the practicality of this book by turning to page 3 (with page 1 being the title) and seeing a code example as the second paragraph of the first chapter. Writing a basic GUI application in C++/Qt is attractively easy, to win you over and make you read the rest of the chapter, as well as finish the basic introduction by creating a windowed application with SpinBox and Slider widgets.

The table of contents is available on the publisher's Web site and looks fairly simple. Each chapter takes about 20-30 pages, with screenshots and code examples provided as part of the text. Reading the first 5 chapters, which comprise the "Basic Qt" section and take up 110 pages, should be enough for any C++ developer to build a sufficiently complex GUI application if all that's required is some graphical interface slapped on top of the functionality that's already there.

The rest of the book -- "Intermediate Qt" chapters -- take the reader into the common problems of GUI development, providing some insight into more advanced topics as well. Supporting networking, working with graphics and images, internationalization of the software application, interacting with help, reading XML through SAX and DOM APIs, accessing databases and doing inter-process communication are all covered here. The authors tended to avoid inserting huge amounts of reference material into the book, and, for example, in the XML chapter when working with Unicode you will be told to go online and download the numeric values of the Unicode characters instead of dedicating valuable book pages to it.

The language of the book is simple to follow; there are plenty of code examples (with discussion following each), and when the authors make certain choices, they also explain why. The diagrams and screenshots are clear (although not in color), and the code examples can be easily separated from the text. This is the first official TrollTech guide to Qt 3.2 programming, and the authors promise that the techniques will work with Qt 4.

Perhaps part of the positive impression that this book left is the fact that programming in Qt is easy and straightforward. At the early stages of my education, I started learning GUI programming with MFC, which left an indelible image of complexity and will probably increase psychiatrist bills in the future (to be fair to Microsoft, Windows Forms with .NET is a huge step forward). The book and the Qt library made some complex things sound quite simple and enjoyable to program. As Matthias Ettrich notes in the foreword to this book, the most important point in reasoning why Qt is so popular is "because programmers like it."

The book comes with a CD that contains non-commercial version of Qt 3.2 for Windows/Mac/Linux, Borland C++ 5.5 (Non-Commercial) and trial version of Borland C++ 6.0 compilers, SQLite database engine and book source code. The non-commercial version of Qt 3.2 for Windows can be installed for Borland C++ 5.5, Borland C++ 6.0, Microsoft Visual C++ 6 and Microsoft Visual C++.NET environments. The examples are quite conveniently located in folders with chapter numbers, followed by subfolders with example names.

Whether you're looking for general introduction to GUI development with C++ or trying to learn Qt, having worked with other libraries and toolkits before, this book is a good source of practical information and reference. The book is part of Perens' Open Source Series.

Alex Moskalyuk enjoys reading and reviewing books on programming and tech industry in general. You can read his other reviews on his personal site. You can purchase C++ GUI Programming with Qt 3from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

18 of 428 comments (clear)

  1. non commercial QT? by msh104 · · Score: 2, Interesting

    a non commercial version for windows? I thought there wasn't a non commercial version of qt for windows.

  2. Personally I like wxWindows by LordKazan · · Score: 5, Interesting

    I personally like the wxWindows library. It's fully object oiented and handles all default behaviors for you. It has a very easy to use message handling system and the documentation is excellent (but should include a screenshot of each control for quicker reference). I once wrote apps is pure win32 API.. *puke* [this was before I really got interested in linux] I now refuse to use anything other than wxWindows.

    Advantages of wxWindows:
    Fully Cross Platform
    Easy to learn API
    Object Oriented model is well suited to GUI construction - 1 class = 1 screen object

    You really should check it out - www.wxwindows.org

    --
    If you cannot keep politics out of your moderation remove yourself from the Mod Lottery.. NOW!
    1. Re:Personally I like wxWindows by Bruce+Perens · · Score: 4, Interesting
      I think we are going to have a wxWindows book by Julian Smart.

      Bruce

    2. Re:Personally I like wxWindows by Falrick · · Score: 4, Interesting

      You're right, it doesn't cost any money to use in comercial apps, but after just finishing writing a comercial app using it, I feel that I can justifiably say, "You get what you pay for".

      I ported a Qt application to wxWindows because we couldn't afford to buy any more Qt licenses for more developers. Not much had been written in Qt, so it didn't seem like it would be a big deal. But man can I tell you that moving from Qt, where things just worked, to wxWindows was a pain.

      Things as simple as changing the mouse cursor didn't always work (yes, I submitted a bug report along with a fix). wxWindows enforces a particular widget hierarchy which also implies a line of communication (you always communicate up the widget stack through events, and down the widget stack through methods).

      The documentation was not always correct. And so far as being cross platform, a large number of widgets have comments along with them such as, "On Windows, feature X and Y are supported. Using GTK, only Feature X is supported.".

      Extending widgets is not as simple as it should be. I needed a toggle button with an image, so I derived a class from the toggle button class and added a handler for the paint event only to find that no paint event is generated or handled for the toggle button! How the hell it paints itself is beyond me, but placing the same paint handling code into a frame derived class worked fine. This kind of inconsistency drives a developer up a wall!

      Other anoyances include wxWindows changing the colors of my mouse pointers (if I wanted the foreground to be black, I would have made it black!) and the limitation of two color mouse pointers. I had full color mouse pointers in Qt so there should be some way of doing it in wxWindows.

      That being said, I did like some of the features of wxWindows. The event handler stack is a neat implementation and I ended up using it heavily. It was easy to add my own event types, though this is another case where some of the documentation is just flat out wrong.

      --
      something clever
  3. KAutoConfig by IceFox · · Score: 4, Interesting
    Just a note for those Qt devs who are doing cross platform work. I have abstracted out KAutoConfig from KDE and made it into its own LGPL library recently and can be downloaded here to use in your free and commercial applications. (Stop wasting your time re-inventing the wheel!)

    [Speal about what it is/does]

    Do you want to add a full fledged configure dialog to your Qt application by only writing one, twenty line function? If so than the KAutoConfig library is what you want. KAutoConfig is several classes that enables a developer to easily create a configure dialog for their applications. It automatically syncs GUI widgets values with values in the configuration file. It does this by looking for keys and widgets that have the same name. It obtains the default values from the initial values of the widgets. KAutoConfigDialog also manages all of the buttons in a normal configure dialog.

    -Benjamin Meyer

    --
    Do you changes clothes while making the "chee-chee-cha-cha-choh" transformation sound?
  4. Qt. by Cave+Dweller · · Score: 5, Interesting

    Qt is probably the best C++ GUI toolkit out there. In my experience, developing an application is extremely easy and straightforward, due to the fact that the people at TT used the simple (yet effective) model of slots and signals. Writing a new event handler is as simple as overriding a method and then connecting it to your widget -- simple as that.

    Not to mention the great I18N possibilities, the great XML-based Qt Designer application, etc, etc.

    All in all, there are very few drawbacks to Qt, other than the commercial price -- but hey, if you're an open source developer, you get it for free. Otherwise, your employer will get his money's worth back -- simply due to the fact that Qt is such an excellent product.

    (No, I don't work for TT -- I just enjoy their products very much)

    1. Re:Qt. by f0rt0r · · Score: 2, Interesting

      I wish I had mod points. When I first looked at cross-platform development, I resisted QT because it was commercial ( and cost $$$ ), so I tried out Java. I hit too many road blocks with Java so I tried C++ with wxWindows. I couldn't find any decent documentation, and everything I did find was very convoluted. Support was websites and mailing lists, neither of which answered even a single question I had.

      Finally I said "What the heck, let me try QT", and I was awed by how simple it was to get it to work. It even intergrated with MS Visual C++ which is my preferred IDE for Windows, with Linux I had to doa bit more work setting the paths, but I found lots of help in the mailing list and the QtForum.org site. All I can say, is for the headaches it has saved me, it is worth the licensing fees. Plus the included documentation is awesome, easily matching that of Java, plus there are a few books out for it, I am currently using SAMS "QT Programming in 24 hours" off and on during develipment.

      En sum, QT is easy to install, easy to get up and running, and has excellent documentation.

      --
      I can't afford a sig!
  5. Licensing Fears by Anonymous Coward · · Score: 1, Interesting


    This is not to be intended as a rant. The thing that scares me about Qt is taking the time to learn it and then one day they decide not to offer a GPL version anymore. At least with GTK+ I know that it is 100% Open Source. I can write apps and even sell them without paying a royalty other than donating to support the cause.

  6. The two major things that turned me off ... by Anonymous Coward · · Score: 1, Interesting
    ...last time I looked at Qt were.

    the meta-object compiler

    non-standard classes, e.g. string

    The bad news is that the lack of standardization plays right into Redmond's game. "Keep them injuns fragmented, and we'll never get pushed into the ocean".
    It hurts Open Source in general, and C++ in particular.
    Qt is clearly a fantastic toolkit, if the success of KDE is any measure.
    Now, if TrollTech had hair one, they would tidy up their free version (in terms of code and licensing) and submit it to Boost. Probably partitioned into a 'lite' version for cross-platform purposes, and a 'pro' version to keep the business model afloat.
    Juat my $0.02

  7. Qt / GTK by The+Night+Watchman · · Score: 2, Interesting

    I'm a programmer, but not a GUI developer, so my knowledge of such things is limited. I've used Qt applications, and I've used GTK applications. Personally, I like GTK2, but that's mainly on an aesthetic level, rather than a functional or development level.

    I ask anyone who's developed in either/both of GTK/Qt, and even those with Win32 experience. What advantages does Qt have over the other choices?

    ---

    --
    "Every jumbled pile of person has a thinking part that wonders what the part that isn't thinking isn't thinking of"-TMBG
  8. Language-Neutral GUI by Tablizer · · Score: 3, Interesting

    Why are so many GUI systems still closely coupled with specific languages? Why not divorce the GUI engine from languages? I don't know of any library that has successfuly done that. Although Tk comes close, it still requires a specific interpreter be installed.

  9. I would say Java is less of a "monopoly" than Qt by iamacat · · Score: 2, Interesting

    With Java, there is a free as in beer VM for most platforms and as far as I understand, you can port Sun's code to your platform for free. You can also develop a clean-room VM and call it something other than Java.

    With Qt, it's either an expensive license (my company requires a senior VP approval for any software over $150) or your program is GPLed and Linux-only. I guess a clean room port would be Ok though?

    I chose Java UI + JNI over embedded Qt before for just these reasons. For C++ programming, I just hope OpenStep really takes off.

  10. Programming with Qt - O'Reilly by adamofgreyskull · · Score: 2, Interesting

    Does anyone know how this compares with Programming with Qt from O'Reilly? That was the reccommended text for a Soft module I did last term/semester (whatever the uni chooses to call them this week). I thought it covered pretty much everything I needed..and even touched on the aforementioned XML/DOM/SAX stuff.

  11. Another Wx fan here. Low restrictions. by guidryp · · Score: 2, Interesting

    Ok I only downloaded it 2 days ago. But it looks really good to me and doesn't have Qt restricitons. After buy both Borland C++ builder and VisC++ I now plan to use only Wx.

    Quote from the FAQ:
    " ...basically you can distribute proprietary binaries without distributing any source code, and neither will wxWindows conflict with GPL code you may be using or developing with it. The conditions for using wxWindows 2 are the same whether you are a personal, academic or commercial developer."

  12. Qt4? by SlayerDave · · Score: 2, Interesting

    There was a Slashdot post a few months ago about Qt4 which stated that Qt4 was scheduled to be released in early 2004. Does the publication of this book indicate that the Qt4 release date has been pushed back? I hope not, because some of the proposed changes in Qt4 seem interesting, especially the introduction of model/view architecture for the table, list, and tree view widgets.

    1. Re:Qt4? by Capt.+Beyond · · Score: 2, Interesting

      I dont think there ever has been a date scheduled for Qt 4 release. Any information you may have gotten about Qt 4, was not official.
      Stay tuned...

      --
      -- "Perceptions create reality. By changing your perceptions you change your reality."
  13. Re:Someone buy Trolltech and LGPL it...PLEASE! by yerM)M · · Score: 2, Interesting
    This really seems like you trying to get something for nothing. Just so we are on the same page, I also develop for an academic institution. There are plenty of good widget systems that are free to use, wxWindows comes to mind for instance. It just boils down to the fact that you don't want to release your source code.

    Trolltech has a free as in freedom liscense, take it or leave it. I have a lot of respect for them for doing this. Their source code is released and open to the public. They seem to have made a compelling product since you would like to use it. This is the dream for most programmers :)

    You mention shareware as a way for developers getting payed but in the same breath don't want to pay TrollTech for their work.

    Okay, this is a bit harsh, I think, based on your post. What do you think should be a per-seat price for TrollTech? Here is a potential alternative: BlackAdder, which is an integrated Qt + Python gui designer and runtime, runs at $400 a seat or $300 a seat for a developer networks. Python + Qt royalty free = $400 = yummy.

    By the way, having no real relevance to your post, as someone who works in academia and insists that every government funded program that I work on releases open source software, I'm assuming your proposals would involve seeking government grants which, by the way, I pay for in taxes. Why isn't grant funded source code GPL'd in the first place since I'm paying taxes for it?

  14. Re:C++ by myzz · · Score: 2, Interesting
    The sorry thing about C++ programming is, that almost nobody knows enough about it to make it useful. It is a very powerful and efficient language for smart programmers, who know the whole C++ language and have learned how this can be used. Also, a standard C++ should be learned, not something that was done by C++ compilers ten years ago... C++ ten years ago was quite pathetic and not the same thing as current C++.

    Some points:

    • OO-programming and C++ classes.

      Everybody thoughs that C++ should be an OO language. C++ is quite bad about OO (as imho is also Java... the main Java advantage is having an inbuilt garbage collector, so you don't need to create you're own reference counting template or something similar, as in C++). OO wants more dynamically typed language than C++ and its alikes are. Statically typed OO problem is too much casting into derived types (dynamic_cast in C++ for example).

      The fact is that C++ "classes" are very good for almost anything else but OO in the classic sense (which uses class hiearchies). They are a great way to create a custom data types (about as some smart structs). They can be used for creating something like continuations and for giving some temporary "static" variables to some function group (which are then the class members).

    • Resource allocation is initialization. This shall be burned into every C++ programmers brain...

      If you have something that requires allocating resources and freeing them, it is usually good idea to put it into an C++ class and use constructor/destructor for allocating/freeing the resource. This is very useful together with objects put into stack - the resources are then automatically freed, when you leave the block.

      In a good C++ program you find very few explicit delete usage - and most of these delete's should be in some destructors.

    • Resources shouldn't be "owned" by alone pointers in stack. This creates exception nightmare, where you must use try-catch to free resources when exception comes. When pointers are in wrappers, everything is nice and exceptions cleanup by themselves (since all objects in stack will be destructed, when exception flies through).

      As a sidenote, the resource allocation is initialization thing is the reason why finally is left out of C++ language - finally is not needed when used resources are freed by stack object destructors.

    • Error handling should be done using exceptions in most cases.

      For some reason many C++ programmers ignore exceptions and make their lives hard with this. Since the STL (and new) uses exceptions you cannot avoid them anyway. Ignoring standard exceptions just leads to a flawed program. Inventing your own error handling instead of using exceptions is just an unnecessary additional work to recreate a feature that is inbuilt into language and leads usually to error handling code bloat.

    • C++ compiler creates a working copy constructors and assignement operators for you, when all your class members are value types. And any class with working copy constructors and assignement operators is a good value type for this.

      This is a very useful, but quite a few C++ programmers seem to know about it. It basically means that you may assemble you're data types with very few trouble. The fact that pointers are not a good value types in this context can be often over come using reference counting wrappers for them (but it is usually a good idea to threat these shared pointers as read-only, unless you implement copy-on-write in you're pointer wrapper).

    • Templates are one of the most useful C++ features, giving an ability to reuse code for different data types. STL is a fine example of template usage and libraries like Boost give an idea about what can be done with templates. It is often useful to create some template classes/functions for handling similar operations on different data types (and avoid things like void* and casting in the code).

    Sorry for bad spelling, I'm not a native english speaker.