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.

17 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 MrBlue+VT · · Score: 4, Informative

      Actually, no they aren't. Java source code is compiled to byte code once. From then on that byte code is read by the Java Virtual Machine and executed. The JVM does do some JIT compiling, but it would be wrong to state that you have to recompile every time you run an application.

  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 DAldredge · · Score: 4, Insightful

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

    2. 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

    3. 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
    4. Re:Personally I like wxWindows by Bruce+Perens · · Score: 4, Informative
      I checked with my executive editor. The book will publish this year.

      Thanks

      Bruce

  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)

  5. Re:C++ by ENOENT · · Score: 5, Funny

    Yes, C++ is easy to program once you know the syntax. Unfortunately, even Bjarne only knows about 60% of the syntax.

    --
    That's "Mr. Soulless Automaton" to you, Bub.
  6. Re:non commercial QT? by Keith+Russell · · Score: 4, Informative
    I thought there wasn't a non commercial version of qt for windows.

    There was, then there wasn't, now there is again. Trolltech withdrew the old non-comm version late last year because it was based on 2.3, and every other supported platform/license combination was on 3.x. The book includes a non-commercial version of 3.2 for Windows.

    --
    This sig intentionally left blank.
  7. 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.

  8. This book is under an Open Source license by Bruce+Perens · · Score: 4, Informative
    The text of book is under an Open Source license, as with all books in my series. A few months after publication, both source and unencrypted PDF will be uploaded.

    It's not the policy of my series to publish proprietary software on the accompanying CD. But there is some Borland stuff and a copy of Windows Qt on the CD. This is due to a mis-communication with my publisher. I found out about it very late in the process (as I was reading a galley proof), and decided to allow the deviation from policy this time rather than cause a tremendous hassle for Troll Tech. The book had already been advertised, and orders had been booked from stores, etc.

    Thanks

    Bruce

  9. Re:Four things I don't care about! by mcpkaaos · · Score: 5, Funny

    1) C++ (Because I can do everything in C)

    That carries about as much weight as saying, "I don't care about women because I can do everything with my hand."

    --
    It goes from God, to Jerry, to me.
  10. 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."
  11. Re:C++ by ENOENT · · Score: 4, Funny

    I used to think that Perl's syntax was easy to understand, until I actually saw some Perl code.

    --
    That's "Mr. Soulless Automaton" to you, Bub.