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.

33 of 428 comments (clear)

  1. Re:SCOde? by 10Ghz · · Score: 3, Informative

    SCO and Canopy combined own a bit over 5% of TT. Majority of the company is owned by the employees of TT. SCO/Canopy can in no shape or form control TT. And TT can't buy the shares back if SCO/Canopy is unwilling to sell.

    So quit your whining.

    --
    Lesbian Nazi Hookers Abducted by UFOs and Forced Into Weight Loss Programs - -all next week on Town Talk.
  2. Re:non commercial QT? by Dave_bsr · · Score: 2, Informative

    You can use QT as long as your applications are non-commercial, as I recall. You could always RTFL - Read teh Friendly License.

    --


    Who is this Anonymous Coward character, how does he post so much, and why is he always such a whore?
  3. Before Java? by OYAHHH · · Score: 2, Informative

    Given Trolltech doesn't even have a website on archive.org prior to the year 2000 I find it a tad bit hard to believe that Sun was later in it's definition of write-once-run-anywhere.

    Plus, if we're gonna play those games then I was using Motif on variety of platforms in the early/mid nineties with C without a need for re-write.

    So I hardly think QT is a defining standard for write-one-run-anywhere GUI development.

    --
    Caution: Contents under pressure
    1. Re:Before Java? by vurian · · Score: 3, Informative

      In 1996 Linux Journal published its first article on developing with Qt: http://www.linuxjournal.com/article.php?sid=0201. By that time, Qt had already been in development for four years, and Troll Tech was 2 1/2 years old.

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

  5. Warning for "Qt Programming" by eddy · · Score: 3, Informative

    I had the misfortune to read a book on Qt by Patrick Ward called Qt Programming. I'm sorry, but it's got to be one of the worst books on this topic that I've ever seen.

    Stay far, far away from it.

    --
    Belief is the currency of delusion.
  6. Re:C++ by __past__ · · Score: 3, Informative
    I completely disagree. C++ syntax is horribly complicated, with many corner cases (one could say the same about its semantics). Creating a correct C++ parser is damn hard, probably only Perl is as hard to parse correctly.

    And if its portability would be so great, why did complete, standards-compliant compilers only get available recently? Why do many projects choose not to use exceptions or even templates to avoid portability problems?

    Oh, and no, you cannot easily call C++ from other languages, unless you take the time to create 'extern "C"' wrappers for all functions, either manually or with some tool like swig. Otherwise name mangling, which is not standardized across implementations will bite you. You cannot even generally link two libraries compiled with different C++ compilers together.

  7. 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.
  8. Re:Qt != write once, run anywhere by Anonymous Coward · · Score: 1, Informative

    actually java classes are recompiled on every platform, every time you run them.

    Not every time. At least with the Hotspot compiler. The n-th time a method is run it is identified as a target for optimization and the bytecode internally recompiled by the JVM. Until then the bytecode is interpreted.

    Your statement is true for the older JIT which is used for the .NET architecture.

    end of nitpick.

  9. Re:write once, runanywhere is more than a GUI tool by Waffle+Iron · · Score: 2, Informative
    You need abstractions to basically the whole underlying OS, which is something the Java class library provides.

    However, the generic OS interfaces provided by the Java class library don't cover much more ground than what the POSIX-ish API subset provided by Windows covers. So you can already write relatively portable code in C++ that will run on both *nix and Windows.

    At any rate, if you're willing to drink the Qt kool-aid, Qt itself provides a bunch of portable generic utility classes to address this same issue.

  10. Re:Personally I like wxWindows by LordKazan · · Score: 2, Informative

    [for those who don't see it DAldredge mentioned what i forgot]
    like DAldredge said - wxWindows doesn't cost you money, ever. And your comment about "maybe you get what you pay for" is absurd.

    SciTech Display doctor was written using wxWindows - here is a screen shot: http://www.wxwindows.org/screen50.htm

    Even AOh3ll uses wxWindows in their apps

    --
    If you cannot keep politics out of your moderation remove yourself from the Mod Lottery.. NOW!
  11. 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

  12. Re:non commercial QT? by arkanes · · Score: 2, Informative
    It's worth noting that the non-commercial versions are binary-only. Not an issue for many people, of course, but I like having source code for my libraries (if only because I like to know whats going on if something doesn't work).

    Also, this non-commercial version does not appear to be available on the Trolltech website, so you'll need to get the book (and the text of the license for it doesn't appear to be available either, although I'd assume it's similiar to the 2.3 non-comm license).

  13. Re:Qt. by Jeremi · · Score: 2, Informative
    Qt relies on moc or something like that to preprocess C++ source files for signals & slots??


    This is true, but it's not a problem in practice. Qt's qmake program generates a nice makefile for each platform that handles all the details for you, and you never really notice the moc files are there.

    --


    I don't care if it's 90,000 hectares. That lake was not my doing.
  14. Re:non commercial QT? by pclminion · · Score: 0, Informative
    You can use QT as long as your applications are non-commercial, as I recall.

    You recall wrong. There is no free Windows QT, even for non-commercial purposes.

    I complained about this years ago to TrollTech, and the response was "Why the hell would anyone want to create free Windows software?"

    A non-commercial, free license for Windows QT is not forthcoming.

  15. Re:Language-Neutral GUI by soullessbastard · · Score: 2, Informative

    and the Aqua widget set (usable from Objective-C, Java and C++ at least

    While the Aqua widget set is accessible from a number of languages in the sense that the buttons look the same, the interfaces across the different languages definitely do not have the same level of parity. An example from Panther is metal buttons which are only accessible from Cocoa/Objective-C. Earlier versions of OS X even had more major interface elements unavailable to Carbon, such as sheets and drawers.

    The underlying widget set of OS X has access from a very wide set of languages, but it's not yet fully language neutral in the sense that new widgets are automatically available in every language. Even though it's been getting better, the choice of APIs still places limits on which subset of the Aqua user interface elements can be used.

    ed

  16. Re:Qt != write once, run anywhere by ajs318 · · Score: 2, Informative

    You're both right and you're both wrong. Even machine level instructions are interpreted. The op-code bits are expanded by a logic array to control the arithmetic and logic unit and the latches at its inputs and outputs. So you could say that there is no such thing as a compiled programme, because it still gets interpreted at some level -- even if that's the level of those AND, OR and NOT gates you spent a whole year on in O-level computer studies.

    The Java Virtual Machine is essentially an interpreter, but what it interprets is designed to be read by a machine and so sacrifices human readability. It would be perfectly possible in theory to design a processor core which executed Java Bytecode natively, and if such a device existed then the JVM would be an emulator for it.

    It also depends on how statefully the interpretation is carried out. Some 8-bit BASIC interpreters were next to stateless, interpreting a programme on a line-by-line basis. This was a necessity when memory was limited and secondary storage was slow. Modern scripting languages such as Perl and Python -- and for that matter, the later Microsoft BASICs -- keep much more state information, almost performing a full compilation.

    --
    Je fume. Tu fumes. Nous fûmes!
  17. Re:Not C++ by arevos · · Score: 2, Informative

    It's incompatable with the STL. But not standard C++.

  18. Re:C++ by Anonymous Coward · · Score: 1, Informative

    There is 2 ways of implementing Exceptions. Structured (SEH) and Exception handling.

    "structured exception handling" and "structured exception" (or "C exception") refer exclusively to the Win32 structured exception handling mechanism provided by Windows. All other references to exception handling (or "C++ exception") refer to the C++ exception handling mechanism. :D Just to add further confusion.

  19. Re:C++ by vurian · · Score: 2, Informative

    That's why I found Accelerated C++ by Koenig and Moo such a good book. It teaches C++ as a coherent language, instead of C with knobs on. On the other hand, it also tries to teach programming an sich, and does that with examples for which Python is better suited. The first edition of Practical C++ by Oualline is a prime example of a book that teaches C++ as a superset of C -- I don't know if the second edtion is as bad. C++ in a Nutshell is perhaps a little too concerned with the pure syntax of C++, and not enough with the meaning of those syntactical constructs.

  20. Re:Qt. by DenOfEarth · · Score: 2, Informative

    That is all well and good, and in theory, it works just fine (well, in practice too, I guess), but the reason that I like to use Qt is that there is a seperate syntax to defining slots and signals. It makes it much easier to read if you skim down your class prototype and the word 'slot' or the word 'signal' appear by themselves. To me that is very clear, and though it requires the use of a precpocessor step, who gives a darn. learn to use a makefile.

    The signals and slots as you've shown look no different from any other class function, and that requires an extra bit of reading to get them right.

    Again, i guess it's all personal preference really.

  21. Re:Personally I like wxWindows by Anonymous Coward · · Score: 2, Informative
    One major difference is that wxWindows creates native controls, not controls that just look like native controls.

    Turns out this can be good or bad, depending on your point of view. Personally, I think it's a good thing.

  22. Re:Language-Neutral GUI by kisielk · · Score: 2, Informative

    Qt has excellent bindings for Python and Perl (and no doubt others, just I've never used them), and arguably, it's much easier to program from Python than it is from C++.

  23. Re:Free windows version?? by JLyle · · Score: 2, Informative
    Just now I checked their website I see no free Windows version at all.

    Correct, it's no longer available. To quote the Qt Free Edition FAQ, "Trolltech supports free software development on platforms where contributing to Free Software/Open Source development is part of the platform strategy. At the time being it does not seem natural for us to release a free edition for Qt/Windows."
  24. Re:Someone buy Trolltech and LGPL it...PLEASE! by Anonymous Coward · · Score: 3, Informative

    With all due respect, you need to clarify your grant/funding issues.

    If you are producing something which is non-commercial, then there should be no issue with the GPL. You aren't selling it, so you don't need to distribute source. Moreover, you are working with a university, which absorbs public funds and has an obligation to contribute to public knowledge and development.

    If the issue is that a private company is using you as a cheap research arm, producing a product for them, then they should easily be able to fork out for a license. You should remember that as a university researcher, you also have a responsiblity to society, even in these circumstances, to attempt to return value back to the public domain.

    Finally, a rudimentary search of the Trolltech web site will show you that there is an educational licensing scheme specifically aimed at universities, which you could take advantage of, for teaching etc.

    Quite simply:
    1) If you want to research, Trolltech will help you out; they'll bend over backwards to help.
    2) If you want to make money, pay them a license and be done with it.

  25. Re:Someone buy Trolltech and LGPL it...PLEASE! by Anonymous Coward · · Score: 1, Informative

    You do know that there is a academic license for Qt as well, don't you?

    And just for bringing that shareware "problem" you should be considered a troll.
    If it where only for the licensing costs, we would see shareware developed for other, gratis, toolkits.

  26. Re:Personally I like wxWindows by VisualStim · · Score: 2, Informative

    Take a look at wxGlade. It's a GUI GUI builder for wxWindows written in Python. It can write out Python, C++ or XRC (XML-like resource code) code.

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

  28. Re:non commercial QT? by baxissimo · · Score: 2, Informative

    Then what do you call this ?

    It's not libre free, but beer free. And it's old as hell. But the poster was correct that there is a "non-commercial" version for windows that's freely available. Be warned though that Trolltech's definition of "non-commercial" is rather peculiar.

    I'm wondering if they'll make this new non-comm 3.2 edition similarly available.

    In the meantime I continue to happily use FOX.

  29. Re:Qt / GTK by StormReaver · · Score: 3, Informative

    "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?"

    I haven't programmed directly in the Win32 API beyond making a few calls from VB (back when I was forced to use that steaming pile...), but the general gist is that it is comparable to Xlib (which I have used a lot in the last year or so). Xlib, and therefore Win32 API, are quite painful to use extensively. Qt is light years easier and friendlier to use than either of the raw APIs mentioned above.

    I had started GUI programming under Linux with GTK+. I used it (and it's C++ counterpart called GTK--, which was the whole reason I learned C++) as much as I could for a couple years before discovering Qt. I have been a Qt programmer since late 1998/early 1999 (or whenever version 1.44 was mainstream).

    Qt, with its support applications (Qt Designer being the cream of the crop); its incredible documentation; and it's thoroughly well-designed API, was a dramatic step forward from GTK+/GTK--. It is, all by itself, a compelling reason to learn C++ if you don't already know it.

  30. Re:Qt != write once, run anywhere by prostoalex · · Score: 2, Informative

    You're over-analyzing it. I taught Java for two years and have used it professionally (although currently it's more of a C world for me), and frankly have little reason for bashing it.

    I just needed some opening line to introduce the concept of Qt's cross-platform nature. If the flamewar was the point, I'd post something like this.

  31. Re:Personally I like wxWindows by arkanes · · Score: 2, Informative
    wxWindows uses Gtk on linux, unless you were running the "Universal" mode. If it looks like crap for you it's because Gtk looks like crap for you.

    The major point of wxWindows is that it uses native, not emulated widgets (unlike all other cross platform toolkits that I'm aware of).

  32. Re:Someone buy Trolltech and LGPL it...PLEASE! by vectra14 · · Score: 2, Informative

    I also work on a university research project (robocup.mae.cornell.edu). We had no problem getting an educational license from Qt. Just apply for an edu license and they'll give you links to the appropriate binaries. (though it may take a bit of time - week to 2 weeks)

    the only difference from the GPL/commercial versions is you don't get the full source. otherwise, exactly all the features of the latest version.

    good luck
    -sergei