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. Qt != write once, run anywhere by vocaro · · Score: 5, Insightful
    Actually, Qt is "Write once, compile anywhere".

    Java class files are fundamentally different because you actually can run them anywhere without recompiling.

    1. Re:Qt != write once, run anywhere by FortKnox · · Score: 5, Insightful

      Before Sun monopolized the notion of 'write once, run everywhere,'

      This line was put up front for one reason. Kick dirt on java to attempt to get the C++ coders respect up front so they'll read my review.

      Notice how Java reviews don't start with "since C++ requires so much double checking and almost certain memory leaks..."

      Just another flame war awaiting to happen.

      --
      Good quote, too many chars. Seriously, the slashdot 120 char limit sucks!
    2. Re:Qt != write once, run anywhere by Slime-dogg · · Score: 2, Insightful

      More like poor coding techniques lead to double-checking and memory leaks. If you force yourself to be strict with your coding style, then you'll find that only on the rarest of instances would you run into memory leaks.

      Too many people are lazy coders, and this has led to a number of leaks, overruns, yada yada yada.

      --
      You need to restart your computer. Hold down the Power button for several seconds or press the Restart button.
  2. Re:Personally I like wxWindows by 10Ghz · · Score: 3, Insightful
    Advantages of wxWindows:
    Fully Cross Platform
    Easy to learn API
    Object Oriented model is well suited to GUI construction


    Doesn't Qt have those same advantages?
    --
    Lesbian Nazi Hookers Abducted by UFOs and Forced Into Weight Loss Programs - -all next week on Town Talk.
  3. Re:C++ by scorpioX · · Score: 2, Insightful

    I'll agree with you on C, but C++ is an wieldy beast compared to the simple elegance of C. If you want to see what C++ should have been, take a look at Objective-C. A true object-oriented language that doesn't break C compatibility in subtle ways. And if the reviewer had ever used NeXT/Apple/GNUStep OpenStep API's, he'd be singing a different tune about how "easy" it is to program GUI code in C++.

  4. Re:Personally I like wxWindows by DAldredge · · Score: 4, Insightful

    wxWindows doesn't cost money if you use it in commerical apps.

  5. Re:C++ by FortKnox · · Score: 2, Insightful

    C/C++ syntax has something going for it; it's very easy to program once you know the syntax

    Umm, I'd say that's a loaded question. Any language is easy to code in once you know the syntax, its the higher thinking that's usually the hurdle, which is why I question why you lumped C and C++ together in your statement. C++ doesn't require you to use objects, but its the reason it was made, right? Someone that knows C and learns some of the C++ syntax and symbols (like the '>>' and such) can program C using C++, but actually writing C++ with classes and objects is much more than throwing code down. Understanding the principles of OO isn't something you just learn through syntax.

    I guess we can argue "programming" a language to mean anything from writing a hello world, to designing a million line enterprise-sized suite of applications, so its probably a perspective thing.

    Anywho, I find your statements are too broad and actually seem karma hungry or trollish.

    --
    Good quote, too many chars. Seriously, the slashdot 120 char limit sucks!
  6. Re:C++ by happyfrogcow · · Score: 4, Insightful

    Why do many projects choose not to use exceptions or even templates

    This is due to the way C++ is generally taught or learned on ones own. Everyone and their mother seems to teach C++ as a C. They might throw in some small sections on classes and encapsulation, and if your lucky virtual methods. But STL? Exceptions? Christ, I didn't even know C++ had exceptions until way after I had read 2 different books on C++ and taken a C++ course. At that point, still no knowledge of C++ exceptions. Then I eventually bought "The C++ Programming Language" by Bjarne and have been completely enlightened by his examples and insight into the language.

    You can't learn C++ by reading K&R.

    Your other points are valid I think, I just wanted to make this point.

  7. Re:Language-Neutral GUI by Glock27 · · Score: 3, Insightful
    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.

    I can think of some that do pretty well: GTK+ (usable from many different languages) and the Aqua widget set (usable from Objective-C, Java and C++ at least - probably more). For that matter, the Windows GUI is accessible from many languages.

    All of them were written in C, which as a simple language, makes interfacing practical/possible. Simplicity has it's virtues. ;-)

    --
    Galileo: "The Earth revolves around the Sun!"
    Score: -1 100% Flamebait
  8. More like bastardized C++ by ajboyle · · Score: 2, Insightful

    Speaking of portability, QT is a bit problematic, as they use non-standard C++ extensions to accomplish their purposes. (Something that the GTK C++ extensions purposely avoided.) Similar to what Microsoft has done with C++.

    C++ has been my language of choice for the past 10 or so years, but it's sad to see the bastardization happening all over by these toolkits.

  9. Someone buy Trolltech and LGPL it...PLEASE! by mrm677 · · Score: 3, Insightful

    QT is awesome. Its license isn't. Before you dismiss this as another ill-informed troll message, consider this:

    I am involved with a university research project. We started developing our app using QT, but had to quickly abandon it due to the GPL issue. Due to complications with funding and grants, we can't currently open-source our project. And we will not be obtaining QT Developer's licenses for the following reasons:

    1. The bureaucratic mess. A proposal would have to be written, alternatives examined, and so forth. This could take too long. This crap is the way many universities work...most software is given to us or obtained very cheaply with academic licenses.

    2. Cost. $1550 goes a long ways in funding graduate students. Our research director would rather hire more students with the money saved. Even Microsoft Visual Studio, which includes far more than GUI widgets, is only a couple hundred bucks for the academic edition.

    I think this is one example of why this is hurting the Linux movement. GTK is LGPL...QT should be the same. I know that TrollTech needs to pay their developers, but I sure wish someone like IBM would buy them out and LGPL QT. For something intregal to a platform, such as GUI toolkits, having to spend $1500 for a license to develop a close-source application just isn't good. Also consider small-time shareware developers. I know that shareware isn't popular in Linux, but its a way for a developer to get payed for creating that unique, niche application

    Of course my arguments are based on my opinion that KDE/QT is superior to Gnome/GTK, and that if it weren't for the license issue, it would be the dominant platform today.

    1. Re:Someone buy Trolltech and LGPL it...PLEASE! by Capt.+Beyond · · Score: 4, Insightful

      The only reason why you would want to use the LGPL, is that you want to keep your code proprietary and to yourself.

      Qt is superior to gtk because it is created by professional developers, not college students.

      Perhaps if you did some research into Trolltech's licenses you would figure out that Trolltech has Edu licenses as well.

      It's LGPL that is hurting Linux, as Linux is about free software, LGPL is only about proprietary software. Do you really want Linux to have more non free, closed source, proprietary software??

      --
      -- "Perceptions create reality. By changing your perceptions you change your reality."
  10. Re:The two major things that turned me off ... by mean+pun · · Score: 2, Insightful
    [I was turned off by] non-standard classes, e.g. string

    Normally, I'd agree, but somehow QString always makes the things I want to do easy, whereas string makes the same thing much more painful. The same goes for Qt container classes versus STL container classes.

    There is a reason for this: the Qt designers have refined these classes over the years, and were willing to abandon old aproaches that didn't work. And they have taste. The STL, on the other hand, is in some places poorly designed, and has been refined very little over the years.

    Compatibility with standards is A Good Thing, but so is having a clean design.

  11. Simple language by InodoroPereyra · · Score: 3, Insightful
    From the review:

    The language of the book is simply to follow

    This is so important. Some of the ... well, probably most of the C++ documentation is so complex that scares people off. Granted, the language is complex. But you can always present documentation in a friendly manner, with examples, and leave subtle points for a separate, advanced discussion. But I have the feeling that some C++ experts want to be part of an elite of a few enlightened people who know it. Too bad because it is a great language.

    In this regard, Qt is a beautiful C++ toolkit, easy to use, really friendly, nicely integrated and documented. Not to mention the great RAD tools like QtDesigner ...

  12. Re:C++ by Bruce+Perens · · Score: 3, Insightful
    I used to think C syntax was easy to understand, until I learned about "Duff's Device".

    Bruce

  13. Re:C++ by Carewolf · · Score: 2, Insightful

    No the reason you didnt learn of exceptions, is to protect you. C++ exceptions are crippled bastards only their mother Bjarne can appreciate.

    If people in generel knew more of C++ exceptions, the C-trolls would have much more ammunition. It is better simple not to talk about them.

    The same goes partly for STL

  14. Re:The two major things that turned me off ... by SupplyChainCoder · · Score: 2, Insightful
    I like the fact that Qt is not so "up to date" with the C++ as Boost.

    When you have to write cross platform applications using the compilers on HP-UX, aCC, SUN & VC then it will be years before all the template usage within Boost will work.

    I wish that the C++ standard was defined in the form of a series of unit tests. That way one could just tell a compiler vendor to fix their compiler when if fails a test.

    These tests should also contain code sections that should not compile according to the standard.

  15. Re:This book is under an Open Source license by Bruce+Perens · · Score: 2, Insightful
    I don't doubt you.

    Make sure you have the right to port that program. No problem if you're the copyright holder. Note that there is a copyright issue regarding porting GPLed KDE programs to commercial Qt on Windows. At the least, you should get written permission from all copyright holders.

    Thanks

    Bruce