504
[ Team LiB ] Table of Contents Index C++ GUI Programming with Qt 3 By Jasmin Blanchette , Mark Summerfield Publisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2 Pages: 464 "...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt' .... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a non- commercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 4 1

C GUI Programming With Qt3.2 2005

Embed Size (px)

Citation preview

[ Team LiB ]

Table of Contents Index

C++ GUI Programming with Qt 3 ByJasmin Blanchette , Mark Summerfield

Publisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2 Pages: 464

"...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 41

Code ] [ Team LiB applications with menus, toolbars, dialogs, and drag and drop Utilize 2D and 3D graphics, multithreading, and networking Write database and XML applications Internationalize to reach foreign markets Exploit platform-specific-features like ActiveX Already using Qt or just starting out? Evaluating Qt or managing it? Building open source applications-or commercial applications? Want to develop for Windows without buying an expensive compiler? Whatever your goal, this is the only book you need! CD-ROM: Everything you need to write great GUI programs! Qt 3.2 Non-Commercial Edition for Windows Table of ContentsIndex

Borland C++ 5.5 Non-Commercial C++ GUI Programming with Qt 3ByJasmin Blanchette , Mark Summerfield Borland C++ 6.0 Trial Edition

Edition

Qt 3.2 Free Editions for Unix/Linux/Mac OS XPublisher: Prentice Hall PTR Pub Date: January 15, 2004 SQLite database

The book's code examples Pages: 464 [ Team LiB ] "...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 42 1

ISBN: 0-13-124072-2

[ Team LiB ]

Table of Contents Index

C++ GUI Programming with Qt 3 ByJasmin Blanchette , Mark Summerfield

Publisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2 Pages: 464

Copyright

"...not only the best Source on Qt I have ever seen, but also the best book presenting any Bruce Perens' Open book Series programming framework. Every sentence appears to be carefully worded, and every chapter Foreword has a sound concept, and so does the work as a whole." Preface -Matthias Ettrich, Trolltech's lead developer, founder of the KDE projectAcknowledgments

"The A Brief of Qt'.... Qt 'Tao History of The Qt system is a beautiful example of object oriented design, and the About the advantage of this.... The authors have done an excellent job of presenting the authors take Authors subject in an interesting and engaging way...." Production -Ron About the CD-ROM McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College Part I: Basic Qt The first official Trolltech guide to Qt 3.2 programming!Hello Qt Making Connections Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x andReference Documentation Using the C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is 2. Creating Dialogs the documentation. You'll find start-to-finish coverage packed Chapter not a rehash of with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a nonSubclassing QDialog commercial Qt 3.2 for Windows available nowhere else! Signals and Slots in Depth Rapid Dialog Design Shape-Changing Dialogs Build powerful C++ GUI applications quickly and easily Dynamic Dialogs Chapter 1. Getting Started

Design dialogs and Dialog Classes Built-in Widget and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanismChapter 3. Creating Main Windows

Use Subclassing QMainWindow layouts to create forms that automatically size and scaleCreating Menus and Toolbars

Create custom the File Menu Implementing signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 43 1Setting Up the Status Bar

Using [ Team LiB ] Dialogs Storing Settings Multiple Documents Splash Screens Chapter 4. Implementing Application Functionality The Central Widget Subclassing QTable Loading and Saving Implementing the Edit Menu Implementing the Other Menus Subclassing QTableItem Chapter 5. Creating Custom Widgets

Table of Contents Customizing Qt Widgets

Index Subclassing QWidget C++ GUI Programming with Qt 3 Integrating Custom Widgets with Qt DesignerByJasmin Blanchette , Mark Summerfield Double Buffering

Publisher: Intermediate PTR Part II: Prentice Hall Qt Pub Date: January 15, 2004 Chapter 6. Layout Management ISBN: 0-13-124072-2 Basic Layouts Pages: 464 Splitters Widget Stacks Scroll Views

"...not only the best book on Qt I have ever seen, but also the best book presenting any Multiple Document Interface programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." Chapter 7. Event Processing -Matthias Ettrich, Trolltech's lead developer, founder of the KDE projectReimplementing Event Handlers

Dock Windows

"The 'TaoInstalling Event Filters system is a beautiful example of object oriented design, and the of Qt'.... The Qt authors take advantage of this.... The Processing have done an excellent job of presenting the Staying Responsive During Intensive authors subject in an interesting and engaging way...." -Ron McCarty,8. 2D and 3D and Chair of the Department of Computer Science, Penn State Erie, Chapter Instructor Graphics The Behrend College Painting with QPainterGraphics with QCanvas The first official Trolltech guide to Qt 3.2 programming! Printing

Straight from Trolltech, this book covers all you need to build industrial-strength applications Graphics with OpenGL with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux Drag and Drop Chapter 9. with no source code changes! The book teaches solid Qt programming practices; it is not a and Drop of the documentation. You'll find start-to-finish coverage packed Enabling Drag rehash with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a nonSupporting Custom Drag Types commercial Qt 3.2 for Windows available nowhere else!Advanced Clipboard Handling Chapter 10. Input/Output Build powerful C++ GUI applications quickly and easily Reading and Writing Binary Data

Design dialogs and main windows visually and in code Reading and Writing Text Learn Qt's innovative typesafe signals and slots mechanismInter-Process Communication Handling Files and Directories

Use layouts to create forms that automatically size and scaleChapter 11. Container Classes

Create custom signals, slots, events, and controls Vectors Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 4Maps Lists

4 1

Pointer-Based Containers [ Team LiB ] QString and QVariant Chapter 12. Databases Connecting and Querying Presenting Data in Tabular Form Creating Data-Aware Forms Chapter 13. Networking Using QFtp Using QHttp TCP Networking with QSocket UDP Networking with QSocketDevice

Chapter 14. of Contents Table XML Reading XML with SAX Index

C++ GUI Programmingwith DOM3 Reading XML with Qt Writing XML ByJasmin Blanchette , Mark Summerfield Chapter 15. Internationalization Publisher: Prentice Hall PTR Working with Unicode Pub Date: January 15, 2004Translation-Aware Making Applications ISBN: 0-13-124072-2 Switching Dynamic Language Pages: 464 Translating Applications Chapter 16. Providing Online Help

"...not only the best bookas a Simple Help Engine seen, but also the best book presenting any on Qt I have ever Using QTextBrowser programming framework. Every sentence appears to be carefully worded, and every chapter Using Qt Assistant for Powerful Online Help has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE projectChapter 17. Multithreading

Tooltips, Status Tips, and "What's This?" Help

"The 'TaoWorking withThe Qt system is a beautiful example of object oriented design, and the of Qt'.... Threads authors take advantage of this.... The authors have done an excellent job of presenting the Communicating with the GUI Thread subject in an interestingin Non-GUI Threadsway...." Using Qt's Classes and engaging -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College Chapter 18. Platform-Specific Features The first official Trolltech guide to Qt 3.2 programming!Using ActiveX Session Management Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming Appendix A. Installing Qt practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed A Note on Licensing with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a nonInstalling Qt/Windows commercial Qt 3.2 for Windows available nowhere else! Installing Qt/Mac Installing Qt/X11 Interfacing with Native APIs

Build powerful C++ GUI applications quickly and easilyAppendix B. Qt's Class Hierarchy

Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism [ Team LiB ] Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 45 1Index

[ Team LiB ]

CopyrightLibrary of Congress Cataloging-in-Publication Data A CIP catalog record for this book can be obtained from the Library of Congress Editorial/Production Supervision: Kathleen M. Caren Cover Design Director: Jerry Votta

Art Director: Gail Cocker-BoguszTable of Contents Index Manufacturing Buyer: Maura Zaldivar

C++ GUI Programming with Qt 3

Acquisitions Mark Summerfield ByJasmin Blanchette ,Editor: Jill Harry Editorial Assistant: Brenda MulliganPublisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2

Marketing Manager: Dan Depasquale

Copyright 2004 Trolltech AS Pages: 464 Published by Pearson Education, Inc. Publishing as Prentice Hall Professional Technical Reference Upper Saddle River, New Jersey 07458 "...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter Thisa sound concept, and so does the subject to the terms and conditions set forth in the Open has material may only be distributed work as a whole." Publication License, v1.0 or later (the latest version is available at -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project http://www.opencontent.org/openpub/). "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the Prentice Hall PTR offers this.... The discounts ondone an excellent job of presenting the authors take advantage of excellent authors have this book when ordered in quantity for bulk purchases or special sales. For more information, please contact: subject in an interesting and engaging way...." U.S.Corporate and Government Sales, Department of Computer Science, Penn State Erie, -Ron McCarty, Instructor and Chair of the 1-800-382-3419, [email protected]. For sales outside of the U.S., please contact: The Behrend College International Sales, 1-317-581-3793, [email protected]. The first official Trolltech guide to Qt 3.2 programming! Trolltech, Qt, and the Trolltech logo are registered trademarks of Trolltech. OpenGLis a trademark of Silicon Graphics, Inc. in theall you need to and other countries. All other company Straight from Trolltech, this book covers United States build industrial-strength applications and product names mentioned herein are the trademarks or registered trademarks OStheir with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac of X, and respective owners. embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed The authors, copyrightCD with the Qt 3.2 toolset and Borland C++ compilers-including a nonwith examples, plus a holder, and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any else! and assume no responsibility for errors commercial Qt 3.2 for Windows available nowhere kind or omissions. The information in this book is furnished for informational use only, is subject to change without notice, and does not represent a commitment on the part of the copyright holder or the publisher. No liability is assumed for and easily or consequential damages in Build powerful C++ GUI applications quickly incidental connection with or arising out of the use of the information or programs contained herein. Design dialogs and main windows visually and in code The software described in this book is furnished under a license agreement or non-disclosure agreement. Qt's innovative typesafe signals and slots mechanism Learn The software may be used or copied only in accordance with the terms of the agreement. Use layouts to create forms that automatically size and scale Printed in the United States of America Create custom signals, slots, events, and controls First Printing Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 46 1

PearsonLiB ] [ Team Education Ltd. Pearson Education Australia Pty., Limited Pearson Education Singapore, Pte. Ltd. Pearson Education North Asia Ltd. Pearson Education Canada, Ltd. Pearson Educacin de Mexico, S.A. de C.V. Pearson Education-Japan Pearson Education Malaysia, Pte. Ltd. [ Team LiB ]

Table of Contents Index

C++ GUI Programming with Qt 3 ByJasmin Blanchette , Mark Summerfield

Publisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2 Pages: 464

"...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 47 1

[ Team LiB ]

Bruce Perens' Open Source SeriesC++ GUI Programming with Qt 3 Jasmin Blanchette, Mark Summerfield Managing Linux Systems with Webmin: System Administration and Module Development Jamie Cameron Understanding the Linux Virtual Memory Manager Mel GormanTable of Contents Index Implementing CIFS: The Common Internet File System

C++ GUI Programming with Qt 3 Christopher R. Hertel ByJasmin Blanchette , Mark Summerfield

Embedded Software Development with eCos Anthony J. MassaPublisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2

Rapid Application Development with Mozilla Nigel McFarlanePages: 464 The Linux

Development Platform: Configuring, Using, and Maintaining a Complete Programming Environment Rafeeq Ur Rehman, Christopher Paul Intrusion best book on Qt I with ever seen, but also the best book presenting any "...not only theDetection Systems have Snort: Advanced IDS Techniques with Snort, Apache, MySQL, framework. Every sentence appears to be carefully worded, and every chapter programming PHP, and ACID has aRafeeq concept, and so does the work as a whole." sound Ur Rehman -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project The Official Samba-3 HOWTO and Reference Guide John H. Terpstra, Qt system is a beautiful example of object oriented design, and the "The 'Tao of Qt'.... The Jelmer R. Vernooij, Editors authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." [ Team LiB ] Instructor and Chair of the Department of Computer Science, Penn State Erie, -Ron McCarty, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 48 1

[ Team LiB ]

ForewordWhy Qt? Why do programmers like us choose Qt? Sure, there are the obvious answers: Qt's single-source compatibility, its feature richness, its C++ performance, the availability of the source code, its documentation, the high-quality technical support, and all the other items mentioned in Trolltech's glossy marketing materials. This is all very well, but it misses the most important point: Qt is successful because programmers like it. How come programmers like one technology, but dislike another? Personally, I believe software engineers enjoy technology that feels right, but dislike everything that doesn't. How else can we explain that some of the brightest programmers need help to program a VCR, or that most Table of Contents engineers seem to have trouble operating the company's phone system? I for one am perfectly Index capable Programming with Qt 3 of memorizing sequences of random numbers and commands, but if these are required C++ GUI to control my answering machine, I'd prefer not to have one. At Trolltech, our phone system ByJasmin Blanchettethe '*' key pressed down for two seconds before we are allowed to type in the forces us to hold ,Mark Summerfield other person's extension number. If you forget to do this but start typing the extension immediately, you have to dial the entire number again. Why '*'? Why not '#', or '1', or '5', or anyPublisher: Prentice Hall PTR of the other twenty keys on the phone? Why two seconds and not one, or three, or one andPubhalf? Why anything at all? I find the phone so irritating that I avoid using it whenever I a Date: January 15, 2004 ISBN: 0-13-124072-2 can. Nobody likes having to do random things, especially when those random things apparently depend on some equally random context you wish you didn't have to know about in the first Pages: 464 place. Programming can be a lot like using our phone system, only worse. And this is where Qt comes to the rescue. Qt is different. Qt I one thing, Qt makes also the best book presentingfun. Qt lets "...not only the best book on For have ever seen, but sense. And for another, Qt is any you concentrate on your tasks. When Qt's appears architects faced a problem, they didn't just programming framework. Every sentence original to be carefully worded, and every chapter look a sound concept, and so does the work as a whole." has for a good solution, or a quick solution, or the simplest solution. They looked for the right solution, and thenTrolltech's lead developer, founder of the KDE project granted some of -Matthias Ettrich, they documented it. Granted they made mistakes, and their design decisions didn't pass the test of time, but they still got a lot of things right, and what wasn't Qt'.... The and can be a beautiful example of object oriented design, and the "The 'Tao of right could Qt system iscorrected. You can see this by the fact that a system originally designed to bridge Windows authors have done an unifies modern desktop systems authors take advantage of this.... The 95 and Unix/Motif now excellent job of presenting the as diverse an interesting and engagingand GNU/Linux with KDE. subject in as Windows XP, Mac OS X, way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, Long before Qt became so popular and so widely used, the dedication of Qt's developers to The Behrend College finding the right solutions made Qt special. That dedication is just as strong today and affects everyone who maintains guide to Qt 3.2 programming! The first official Trolltech and develops Qt. For us, working on Qt is a responsibility and a privilege. We are proud of helping to make your professional and open source lives easier and more enjoyable. Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and One of the Linux with no source code changes!use is its online documentation. But the embedded things that makes Qt a pleasure to The book teaches solid Qt programming documentation's focus is primarily on individual classes, find little said about how to packed practices; it is not a rehash of the documentation. You'll with start-to-finish coverage build sophisticated real-world applications. 3.2 excellent book fills C++ compilers-including a nonwith examples, plus a CD with the Qt Thistoolset and Borland that gap. It shows you what Qt has to offer, how to program Qt the "Qt way", and how commercial Qt 3.2 for Windows available nowhere else! to get the best from Qt. The book will teach a C++ programmer how to program Qt, and provides enough advanced material to satisfy experienced Qt programmers. The book is packed with good examples, advice, and explanations, and will be the text that we use to induct all new programmers who join Build powerful C++ GUI applications quickly and easily Trolltech. Design dialogs and main windows visually and in code Nowadays, there are a vast number of commercial and free Qt applications available for Learn download. Some are specialized for particular vertical purchase orQt's innovative typesafe signals and slots mechanism markets, while others are aimed at the mass-market. Seeing so many applications built with Qt fills us with pride and Use layouts to create forms that automatically size and scale inspires us to make Qt even better. And with the help of this book, there will be more and higher quality Qt applications than ever before. Create custom signals, slots, events, and controls Matthias Ettrich Oslo, Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 4 Norway9 1

November 2003 [ Team LiB ] [ Team LiB ]

Table of Contents Index

C++ GUI Programming with Qt 3 ByJasmin Blanchette , Mark Summerfield

Publisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2 Pages: 464

"...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 410 1

[ Team LiB ]

PrefaceThe Qt toolkit is a C++ class library and a set of tools for building multiplatform GUI programs using a "write once, compile anywhere" approach. Qt lets programmers use a single source tree for applications that will run on Windows 95 to XP, Mac OS X, Linux, Solaris, HP-UX, and many other versions of Unix with X11. A version of Qt is also available for Embedded Linux, with the same API. The purpose of this book is to teach you how to write GUI programs using Qt 3. The book starts with "Hello Qt" and quickly moves on to more advanced topics, such as creating custom widgets and Table of Contents and drop. The text is complemented by a CD that contains the providing drag source code Index example programs. The CD also provides Qt and Borland C++ for Windows, of the Qt for Unix, and Qt for Mac3OS X. Appendix A explains how to install the software. C++ GUI Programming with QtByJasmin Blanchette ,on explaining good idiomatic Qt 3 programming techniques rather than The book focuses Mark Summerfield simply rehashing or summarizing Qt's extensive online documentation. And because we are involved in the development of Qt 4, we have tried to ensure that most of what we teach here will Publisher:valid and sensible for Qt 4. still be Prentice Hall PTR Pub Date: January 15, 2004

It is assumed that you have a basic knowledge of C++. The code examples use a subset of ISBN: 0-13-124072-2 C++, avoiding many C++ features that are rarely needed when programming Qt. In the few Pages: 464 places where a more advanced C++ construct is unavoidable, it is explained as it is used. Qt made its reputation as a multiplatform toolkit, but because of its intuitive and powerful API, many organizations use Qt for single-platform development. Adobe Photoshop Album is just "...not only the best book on Qt Windows application written in Qt. Many sophisticated software one example of a mass-market I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter systems in vertical markets, such as 3D animation tools, digital film processing, electronic has a sound concept, and sodesign), oil and as a exploration, financial services, and medical design automation (for chip does the work gas whole." -Matthiasare built Trolltech's lead are makingfounder with a KDE project imaging, Ettrich, with Qt. If you developer, a living of the successful Windows product written in Qt, you can easily create new markets in the Mac OS X and Linux worlds simply by "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the recompiling. authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and licenses. If you want to build commercial applications, you must Qt is available under various engaging way...." -Ron McCarty, Instructor and Chair of to build open source programs, you can use State Erie, buy a commercial license; if you want the Department of Computer Science, Penn a nonThe Behrend College (The editions of Qt on the CD are non-commercial.) Qt is the foundation commercial Qt edition. on which the K Desktop Environment (KDE) and the many open source applications that go The first official Trolltech guide to Qt 3.2 programming! with it are built. Straight from Trolltech, this book covers all you need to build industrial-strength applications In addition to Qt's hundreds of classes, there are add-ons that extend Qt's scope and power. with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and Some of these products, like the Qt/Motif integration module and Qt Script for Applications embedded Linux with no source code changes! The book teaches solid Qt programming (QSA), are supplied by Trolltech, while others are provided by companies and by the open practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed source community. See http://www.trolltech.com/products/3rdparty/ for information on Qt with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a nonadd-ons. Qt also has a well-established and thriving user community that uses the qtcommercial Qt 3.2 for Windows available nowhere else! interest mailing list; see http://lists.trolltech.com/ for details. The book is divided into two parts. Part I covers all theeasily Build powerful C++ GUI applications quickly and concepts and practices necessary for programming GUI applications using Qt. Knowledge of this part alone is sufficient to write useful GUI applications. Part IIwindowscentral Qt topics in more depth and provides more Design dialogs and main covers visually and in code specialized and advanced material. The chapters of Part II can be read in any order, but they assume familiarity with the typesafe signals and slots mechanism Learn Qt's innovative contents of Part I. If you spot errors to create forms that automatically the next edition, or want to give us Use layouts in the book, have suggestions for size and scale feedback, we would be delighted to hear from you. You can reach us at [email protected] and [email protected]. The errata will be Create custom signals, slots, events, and controls placed on http://vig.prenhall.com/catalog/academic/product/0,4096,0131240722,00.html. Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 411 1

[ Team LiB ]

Table of Contents Index

C++ GUI Programming with Qt 3 ByJasmin Blanchette , Mark Summerfield

Publisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2 Pages: 464

"...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 412 1

[ Team LiB ]

AcknowledgmentsOur first acknowledgment goes to Eirik Chambe-Eng, Trolltech's president. Eirik not only enthusiastically encouraged us to write the book, he also allowed us to spend a considerable amount of our work time writing it. Eirik and Trolltech CEO Haavard Nord both read the manuscript and provided valuable feedback. Their generosity and foresight was aided and abetted by Matthias Ettrich, Trolltech's lead developer and our boss. Matthias cheerfully accepted our neglect of duty as we obsessed over the writing of this book and gave us a lot of advice on good Qt programming style. We asked two Qt of Contents Paul Curtis and Klaus Schmidinger, to be our external reviewers. Table customers, Both are Qt experts with an amazing attention to technical detail, which they proved by Index spotting Programmingsubtle errors in our manuscript and suggesting numerous improvements. some very with Qt 3 C++ GUIByJasmin Blanchette , Mark Summerfield Within Trolltech, alongside Matthias, our most stalwart reviewer was Reginald Stadlbauer.[*] His technical insight was invaluable, and he taught us how to do some things in Qt that we didn't even know were possible. Publisher: Prentice Hall PTR[*] Reginald has now moved to Germany, where he co-founded froglogic, a software consultancy. Pub Date: January 15, 2004

Our other key reviewers within Trolltech were Trenton Schulz, Andy Shaw, and Andreas Aardal Pages: 464 Hanssen. Trenton and Andy gave feedback on all aspects of the book and were especially helpful regarding Qt/Mac and Qt/Windows. Andreas gave us invaluable help refining Part I. In addition to the reviewers mentioned above, we received expert help from Warwick Allison "...not only theEirik Chambe-Eng (Qt's history), Matthias Ettrich (event processing and custom (2D graphics), best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, andHugheschapter widgets), Harald Fernengel (databases), Volker Hilsheimer (ActiveX), Bradley every has a sound concept, and so does the work as a and databases), Lars Knoll (2D graphics), Sam (multithreading), Trond Kjernsen (3D graphics whole." Magnuson (qmake), Dimitri Papadopoulos (Qt/X11), of the KDE project -Matthias Ettrich, Trolltech's lead developer, founderPaul Olav Tvete (custom widgets and Qt/Embedded), Rainer Schmid (networking and XML), and Gunnar Sletta (event processing). "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage Trolltech'sThe authors have done an to keep our support load under Extra thanks are due to of this.... support team for helping excellent job of presenting the subject while the book consumed so much of our time, and to Trolltech's system administrators control in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, for keeping our machines running and our networks communicating throughout the project. The Behrend College We are also grateful to Troy Kitch from Borland for giving us permission to include Borland The first official on the accompanying 3.2 programming! C++ compilers Trolltech guide to Qt CD, and to the SQLite developers for putting their database into the public domain. Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt production C++-applications that run nativelythatWindows, Linux/Unix, Mac OS X, and On the 3.2.x and side, Rainer Schmid led the team on created the accompanying CD, ably embedded by Harald Fernengel and Andy Shaw.The book teaches solid Qt handled the contracts supported Linux with no source code changes! Trolltech's Cathrine Bore programming practices; it ison our rehash of the documentation.of the Lout start-to-finish coverage packed and legalities not a behalf. Jeff Kingston, author You'll find typesetting tool, gave us advice with enhanced the toolCDthe light of our feedback. JillBorland C++ compilers-including a the and examples, plus a in with the Qt 3.2 toolset and Harry of Prentice Hall had faith in noncommercial Qt 3.2 for and ensured that all the practical matters were smoothly handled, project from the start Windows available nowhere else! leaving us free to concentrate on the writing. And Lisa Iarkowski turned our camera-ready manuscript into the beautiful volume you now hold in your hands. Build powerful C++ GUI applications quickly and easily [ Team LiB ] Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 413 1

ISBN: 0-13-124072-2

[ Team LiB ]

A Brief History of QtThe Qt toolkit first became publicly available in May 1995. It was initially developed by Haavard Nord (Trolltech's CEO) and Eirik Chambe-Eng (Trolltech's president). Haavard and Eirik met each other at the Norwegian Institute of Technology in Trondheim, Norway, where they both graduated with master's degrees in computer science. Haavard's interest in C++ GUI development began in 1988 when he was commissioned by a Swedish company to design and implement a C++ GUI toolkit. A couple of years later, in the summer of 1990, Haavard and Eirik were working together on a C++ database application for ultrasound images. Contents Table of The system needed to be able to run with a GUI on Unix, Macintosh, and Windows. One day that summer, Haavard and Eirik went outside to enjoy the sunshine, and as Index theyGUI Programming with QtHaavard said, "We need an object-oriented display system." The sat on a park bench, 3 C++ resulting discussion laid the intellectual foundation for the object-oriented multiplatform GUI ByJasmin Blanchette , Mark Summerfield toolkit they would soon go on to build. In 1991, Haavard started writing the classes that eventually became Qt, collaborating with Eirik Publisher: Prentice following year, Eirik came up the ideafor "signals and slots", a simple but on the design. TheHall PTR Pub Date: January 15, 2004 powerful GUI programming paradigm. Haavard took the idea and produced a hand-coded implementation. By 1993, Haavard and Eirik had developed Qt's first graphics kernel and were ISBN: 0-13-124072-2 able to implement their own widgets. At the end of the year, Haavard suggested that they go Pages: 464 into business together to build "the world's best C++ GUI toolkit". The year 1994 began inauspiciously with the two young programmers wanting to enter a well established market, with no customers, an unfinished product, and no money. Fortunately, "...not only the best book on Qt I have ever seen, but also the best book presenting any both their wives had work and were willing to support their husbands for the two years Eirik programming framework. Every sentence appears to be carefully worded, and every chapter and Haavard expected to need to develop the product and start earning an income. has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder looked KDE project Haavard's Emacs font. They chose 'Q' as the class prefix because the letter of the beautiful in The 't' was added to stand for "toolkit", inspired by "Xt", the X Toolkit. The company was "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the incorporated on 4 March 1994, originally as "Quasar Technologies", then as "Troll Tech", and authors take advantage of this.... The authors have done an excellent job of presenting the today as "Trolltech". subject in an interesting and engaging way...." -Ron McCarty, thanks to aand Chair of the Department of Computer Science, Penn State Erie, In April 1995, Instructor contact made through one of Haavard's University professors, the The Behrend College Metis gave them a contract to develop software based on Qt. Around this Norwegian company time, Trolltech hired Arnt Gulbrandsen,[*] who devised and implemented an ingenious The first official Trolltech guide to Qt 3.2 programming! documentation system as well ascontributing to Qt's code. StraightArnt left the company a book covers all pursue his career in Germany. [*] from Trolltech, this few years ago to you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with0.90source code changes! The book teaches solid Qt programming was On 20 May 1995, Qt no was uploaded to sunsite.unc.edu. Six days later, the release practices; iton comp.os.linux.announce. This was Qt's first public release. coverage be used announced is not a rehash of the documentation. You'll find start-to-finish Qt could packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including was for both Windows and Unix development, offering the same API on both platforms. Qt a noncommercial Qt 3.2 for Windows available nowhere else! license was required for commercial available under two licenses fromday one: A commercial development and a free software edition was available for open source development. The Metis contract kept Trolltech afloat, while for ten long months no one bought a commercial Qt Build powerful C++ GUI applications quickly and easily license. Design dialogs and main windows visually and in code In March 1996, the European Space Agency became the second Qt customer, with a purchase of ten commercial licenses. With unwavering faith, Eirik and Haavard hired another developer. Learn Qt's innovative typesafe signals and slots mechanism Qt 0.97 was released at the end of May, and on 24 September 1996, Qt 1.0 came out. By the end of the year, Qt had reached version 1.1; eight customers, each in a different country, had Use layouts to create forms that automatically size and scale bought 18 licenses between them. This year also saw the founding of the KDE project, led by Matthias Ettrich. Create custom signals, slots, events, and controls Qt 1.2 was released in way'' 1997. Matthias Ettrich's decision to use Qt to build KDE helped Qt Program the ''Qt April with techniques for Qt 3.2 that'll work with Qt 414 1

becomeLiB ]de-facto standard for C++ GUI development on Linux. Qt 1.3 was released in [ Team the September 1997. Matthias joined Trolltech in 1998, and the last major Qt 1 release, 1.40, was made in September of that year. Qt 2.0 was released in June 1999. Qt 2 hadmany major architectural changes and was a much stronger and more mature product than its predecessor. It also featured forty new classes and Unicode support. Qt 2 had a new open source license, the Q Public License (QPL), which complied to the Open Source Definition. In August 1999, Qt won the LinuxWorld award for best library/tool. Around this time, Trolltech Pty Ltd (Australia) was established. Trolltech released Qt/Embedded in 2000. It was designed to run on Embedded Linux devices and provided is own window system as a lightweight replacement for X11. Both Qt/Embedded and Qt/X11 were now offered under the widely used GNU General Public License (GPL) as well as under commercial licenses. By the end of 2000, Trolltech had established Trolltech Inc. (USA) and had released the first version of Qtopia, an environment for handheld devices. Table of Contents Qt/Embedded won the LinuxWorld "Best Embedded Linux Solution"award in both 2001 and Index 2002.C++ GUI Programming with Qt 3

QtJasmin Blanchette ,Mark Summerfield By 3.0 was released in 2001. Qt was now available on Windows, Unix, Linux, Embedded Linux, and Mac OS X. Qt 3.0 provided 42 new classes and the code surpassed 500,000 lines. Qt 3.0 won the Software Development Times "Jolt Productivity Award" in 2002.Publisher: Prentice Hall PTR

Trolltech's sales have2004 Pub Date: January 15, doubled year on year since the company's birth. This success is a reflection both of the quality of Qt and of how enjoyable it is to use. For most of the company's ISBN: 0-13-124072-2 existence, sales and marketing were handled by just a couple of people. Yet, in less than a Pages: 464 decade, Qt has gone from being a "secret" product, known only to a select group of professionals, to having thousands of customers and tens of thousands of open source developers all around the world. "...not only ] [ Team LiB the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 415 1

[ Team LiB ]

About the AuthorsJasmin Blanchette Jasmin graduated in computer science in 2001 from the University of Sherbrooke, Quebec, and was awarded the Fernand Seguin medal of excellence. He did a work term at Trolltech in the summer of 2000 as a software engineer and has been working there continuously since early 2001. Now a senior software engineer, he is the driving force behind the Qt Linguist translation tool and provides Qt Quarterly, Trolltech's technical newsletter, with much of its content. In his spare time, he is writing a novel in Norwegian and Swedish. He lives in Oslo with his girlfriend Anne-Lene. Table of Contents

Mark Summerfield

Index

C++ GUI Programming with Qt 3 ByJasmin Blanchette , Mark Summerfield Mark graduated in computer science in 1993 from the University of Wales Swansea. He followed this with a year's postgraduate research before going into industry. He spent many years working as a software engineer for a variety of firms before joining Trolltech. For the Publisher: Prentice has been Trolltech's documentation manager, responsible for maintaining past few years, he Hall PTR over 1500 pages of online Qt documentation and for editing Qt Quarterly. In his free time, he Pub Date: January 15, 2004 writes open 0-13-124072-2 ISBN: source software. He lives in the Swansea Valley in South Wales, UK, with his wife Andrea. Pages: 464

[ Team LiB ] "...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 416 1

[ Team LiB ]

ProductionThe authors wrote the text using NEdit and Vim. They typeset and indexed the text themselves, marking it up with a modified Lout syntax that they converted to pure Lout using a custom preprocessor written in Python. They produced all the diagrams in Lout and used ImageMagick to convert screenshots to PostScript. The monospaced font used for code is derived from Courier and was created using PfaEdit. The cover was provided by the publisher; the photograph is of the fall of the Berlin Wall, November 1989. The marked-up text was converted to PostScript by Lout, then to PDF by Ghostscript. The authors did all the editing and processing on Debian GNU/Linux systems under KDE. The example programs were tested on Windows, Linux, and Mac OS X. Table of Contents

[ Team LiB ] C++ GUI Programming with Qt 3ByJasmin Blanchette , Mark Summerfield

Index

Publisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2 Pages: 464

"...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 417 1

[ Team LiB ]

About the CD-ROMThe CD-ROM included with C++ GUI Programming with Qt 3 contains all the software and source code needed to create and run applications on Windows, Mac OS X, and Unix/Linux with X11. The CD-ROM includes the following: Qt 3.2.1 Non-Commercial Edition for Windows Qt 3.2.1 Free Edition for Mac OS X Table of Contents Qt 3.2.1 Free Edition for Unix/Linux with X11 Index

C++ GUI Programming with Qt 5 Borland C++ Builder 3

Non-Commercial Edition

ByJasmin Blanchette , Mark Summerfield

Borland C++ Builder 6 Trial Edition Source code for the book's examples

Publisher: Prentice Hall PTR

Pub Date: of Qt 15, 2004 All versions Januarycome with the Qt library and a set of tools including the qmake build tool, Qt ISBN: visual dialog Designer for0-13-124072-2 design, Qt Linguist for internationalization support, and Qt Assistant Pages: 464 for presenting documentation.

The CD-ROM can be used on Microsoft Windows 95, 98, NT 4, ME, 2000, XP, Mac OS X, Linux, and most versions of Unix. "...not only the best book on Qt I have ever seen, but also the best book presenting any License Agreement programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." Each of the software packages on the CD-ROM has its own license agreement. The full legal -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project texts of the licenses are included with the packages on the CD-ROM. "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the Technical Support authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." Neither Prentice Hall nor Trolltech offers any technical support for any of the software on the -Ron McCarty, Instructor and Chair of the Department ofavailable from Trolltech; fully Erie, CD-ROM. (Fully supported commercial editions of Qt are Computer Science, Penn State The Behrend College editions of Borland C++ Builder are available from Inprise.) If the CDsupported commercial ROM is damaged, you can obtain a replacement copy by sending an email that describes the The first official Trolltech guide to Qt 3.2 programming! problem to [email protected]. Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and [ Team LiB ] embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 418 1

[ Team LiB ]

Part I: Basic QtChapter 1. Getting Started Chapter 2. Creating Dialogs Chapter 3. Creating Main Windows Chapter 4. Implementing Application Functionality Table of Contents Chapter 5. Creating Custom Widgets Team LiB ]Index [C++ GUI Programming with Qt 3 ByJasmin Blanchette , Mark Summerfield

Publisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2 Pages: 464

"...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 419 1

[ Team LiB ]

Chapter 1. Getting StartedHello Qt Making Connections Using the Reference Documentation This chapter shows how to combine basic C++ with the functionality provided by Qt to create a few small graphical user interface (GUI) applications. This chapter also introduces two key Qt Table of Contents ideas: "signals and slots" and layouts. In Chapter 2, we will go into more depth, and in Chapter we will start building a realistic application. Index 3,C++ GUI Programming with Qt 3

[ Team LiB ] ByJasmin Blanchette , Mark Summerfield

Publisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2 Pages: 464

"...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 420 1

[ Team LiB ]

Hello QtHere's a very simple Qt program:

1 #include 2 #include 3 int main(int argc, char *argv[]) 4 { 5 QApplication app (argc, argv); 6 Table of Contents QLabel *label = new QLabel("Hello Qt!", 0); 7 Index app.setMainWidget(label); C++ GUI Programming with Qt 3 8 label->show(); 9 ByJasmin return app.exec(); Blanchette , Mark Summerfield 10 }Publisher: Prentice Hall PTR

We Pub Date: January 15,line by line, then we will see how to compile and run it. will first study it 2004 Lines 1ISBN: 0-13-124072-2 definitions of the QApplication and QLabel classes. and 2 include thePages: 464

Line 5 creates a QApplication object to manage application-wide resources. The QApplication constructor requires argc and argv because Qt supports a few command-line arguments of its own. "...not only the best book on Qt I have ever seen, but also the best book presenting any Line 6 creates framework. Everythat displays "Helloto be carefully worded, andwidget chapter programming a QLabel widget sentence appears Qt!". In Qt terminology, a every is a visual element in a concept, and soButtons, menus, scroll bars, and frames are all examples of has a sound user interface. does the work as a whole." widgets. Widgets can containlead developer, founder of the KDE project window is usually a -Matthias Ettrich, Trolltech's other widgets; for example, an application widget that contains a QMenuBar, a QToolBar, a QStatusBar, and some other widgets. The 0 argument to the QLabel constructor (a null pointer) means that the widget is a window in "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and theits own right, not a widget of this.... The window. authors take advantage inside another authors have done an excellent job of presenting the subject in an interesting and engaging way...." Line 7 makes the label the application's main widget. When the userScience, Penn State Erie, -Ron McCarty, Instructor and Chair of the Department of Computer closes the main widget (by clicking X in the window's title bar, for example), the program terminates. Without a main The Behrend College widget, the program would keep running in the background even after the user has closed the window. The first official Trolltech guide to Qt 3.2 programming! Line 8 makes the label visible. Widgets are always created hidden, so that we can customize Straight from Trolltech, this book covers all you need to build industrial-strength applications themQt 3.2.xshowing them, thereby that run natively on Windows, Linux/Unix, Mac OS X, and with before and C++-applications avoiding flicker. embedded Linux with no source code changes! The book teaches solid Qt programming Line 9 passes not a of the application on to Qt. At this find start-to-finish enters a packed practices; it is controlrehash of the documentation. You'll point, the program coveragekind of stand-by mode, where it with for Qt 3.2 toolset and Borland clicks and key presses. with examples, plus a CDwaits the user actions such as mouseC++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! User actions generate events (also called "messages") to which the program can respond, usually by executing one or more functions. In this respect, GUI applications differ drastically from Build powerful C++ programs, which typicallyand easily conventional batch GUI applications quickly process input, produce results, and terminate without human intervention. Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism

Figure 1.1. Hello on Windows XP

Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls It is now time to test the program on your machine. First, you will with Qt 4 Program the ''Qt way'' with techniques for Qt 3.2 that'll work need to install Qt 3.2 (or a21 1

later Qt LiB ] [ Team 3 release), a process that is explained in Appendix A. From now on, we will assume that you have a correctly installed copy of Qt 3.2 and that Qt's bin directory is in your PATH environment variable. (On Windows, this is done automatically by the Qt installation program, so you don't need to worry about it.) You will also need the Hello program's source code in a file called hello.cpp in a directory calledhello. You can type in hello.cpp yourself, or copy it from the CD provided with this book, where it is available as \examples\chap01\hello\hello.cpp. From a command prompt, change directory to hello, then type

qmake -project

to create a platform-independent project file (hello.pro), then type Table of Contents Index

qmake hello.pro C++ GUI Programming with Qt 3ByJasmin Blanchette , Mark Summerfield

to create a platform-specific makefile from the project file. Run make to build the program, and run the program by typing hello on Windows, ./hello on Unix, and open hello.app on Mac Publisher: Prentice Hall PTR OS X. If you are using Microsoft Visual C++, you will need to run nmake instead of make. Pub Date: January 15, Alternatively, you can2004 create a Visual Studio project file from hello.pro by typingISBN: 0-13-124072-2 Pages: 464

qmake -tp vc hello.pro

and then build the program in Visual Studio. seen, but also the best book presenting any "...not only the best book on Qt I have ever programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and1.2. A label with basic HTML formatting Figure so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College Now let's have some fun: We will brighten up the label by using some simple HTML-style The first official Trolltech guide to Qt 3.2 programming! formatting. This can be done by replacing the line Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and QLabel *label = new QLabel("Hello Qt!", 0); embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! QLabel *label = new QLabel("Hello " Build powerful C++ GUI applications quickly and easily "Qt!", 0); Design dialogs and main windows visually and in code and rebuilding the application. Learn Qt's innovative typesafe signals and slots mechanism [ Team LiB ] Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 422 1

[ Team LiB ]

Making ConnectionsThe next example illustrates how to respond to user actions. The application consists of a button that the user can click to quit. The source code is very similar to Hello, except that we are using a QPushButton instead of a QLabel as our main widget, and we are connecting a user action (clicking a button) to a piece of code. This application's source code is on the CD in the file \examples\chap01\quit\quit.cpp.

Figure 1.3. The Quit application Table of Contents Index

C++ GUI Programming with Qt 3 ByJasmin Blanchette , Mark Summerfield

1 Publisher: Prentice Hall PTR #include 2 #include Pub Date: January 15, 2004 3 int main(int argc, char *argv[]) 4 { Pages: 464 5 QApplication app(argc, argv); 6 QPushButton *button = new QPushButton("Quit", 0); 7 QObject::connect(button, SIGNAL(clicked()), "...not only the best book on &app, SLOT(quit())); also the best book presenting any Qt I have ever seen, but 8 programming framework. Every sentence appears to be carefully worded, and every chapter 9 app.setMainWidget(button); has a sound concept, and so does the work as a whole." 10 button->show(); -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project 11 return app.exec(); 12 } "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an emit signalsandindicate that a user action or a change of state has occurred. [*] For Qt's widgets interesting to engaging way...." -Ron McCarty, Instructor andaChair of the signal when the user clicks the button. AState Erie, instance,QPushButton emits clicked() Department of Computer Science, Penn signal can The Behrend College be connected to a function (called a slot in that context), so that when the signal is emitted, the slot is automatically executed. In our example, we connect the button's clicked() signal The first official Trolltech guide to Qt 3.2 programming! and SLOT() macros are part of the to the QApplication object's quit() slot. The SIGNAL() syntax; they are explained in more detail in the next chapter. Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt Qt signals are unrelated to Unix signals. In natively on Windows, Linux/Unix,Qt signals.X, and [*] 3.2.x and C++-applications that run this book, we are only concerned with Mac OS embedded Linux with no source code changes! The book teaches solid Qt programming We will now build a rehash of the documentation. you have start-to-finish coverage packed practices; it is notthe application. We assume that You'll find created a directory called quit containingquit.cpp. CD qmake in the quit directory to generate compilers-including run it with examples, plus aRun with the Qt 3.2 toolset and Borland C++the project file, then a nonagain to generate for Windows commercial Qt 3.2a makefile: available nowhere else! Build powerful C++ GUI applications quickly and easily qmake -project qmake quit.pro Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals click Quit, or press Space (which presses the Now build the application, and run it. If you and slots mechanism button), the application will terminate. Use layouts to create forms that automatically size and scale The next example demonstrates how to use signals and slots to synchronize two widgets. The Create custom signals, slots, which and controls application asks for the user's age,events,the user can enter by manipulating either a spin box or a slider. Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 423 1ISBN: 0-13-124072-2

[ Team LiB ]

Figure 1.4. The Age application

The application consists of three widgets: a QSpinBox, a QSlider, and a QHBox (horizontal layout box). The QHBox is the application's main widget. The QSpinBox and the QSlider are rendered inside the QHBox; they are children of the QHBox.

Figure 1.5. The Age application's widgets

Table of Contents Index

C++ GUI Programming with Qt 3 ByJasmin Blanchette , Mark Summerfield

1 2 3 4

#include #include Publisher: Prentice Hall PTR #include Pub Date: January 15, 2004 #include ISBN: 0-13-124072-2Pages: 464

5 int main(int argc, char *argv[]) 6 { 7 QApplication app(argc, argv); "...not only the *hbox = new Qt I have ever seen, but also the best book presenting any 8 QHBox best book on QHBox(0); programming framework. Every sentence appears to be carefully worded, and every chapter 9 hbox->setCaption("Enter Your Age"); has a sound concept, and so does the work as a whole." 10 hbox->setMargin(6); -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project 11 hbox->setSpacing(6); "The 'Tao of Qt'.... *spinBox = new a beautiful example of object oriented design, and the 12 QSpinBox The Qt system is QSpinBox(hbox); authors take advantage of this.... The authors have done an excellent job of presenting the 13 QSlider *slider = new QSlider(Qt::Horizontal, hbox); subject in an interesting and engaging way...." 14 spinBox->setRange(0, 130); -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, 15 slider->setRange(0, 130); The Behrend College 16 QObject::connect(spinBox, SIGNAL(valueChanged(int)), The first official Trolltech guide to Qt 3.2 programming! 17 slider, SLOT(setValue(int))); 18 QObject::connect(slider, SIGNAL(valueChanged(int)), Straight from Trolltech, this book covers all you need to build industrial-strength applications 19 Qt 3.2.x and C++-applications thatSLOT(setValue(int))); Linux/Unix, Mac OS X, and spinBox, run natively on Windows, with 20 spinBox->setValue(35); changes! The book teaches solid Qt programming embedded Linux with no source code practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed 21 examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a nonapp.setMainWidget(hbox); with 22 hbox->show(); commercial Qt 3.2 for Windows available nowhere else! 23 return app.exec(); 24 } Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Lines 8 to 11 set up the QHBox.[*] We call setCaption() to set the text displayed in the Learn Qt's innovative put some space (6 pixels) around and window's title bar. Then wetypesafe signals and slots mechanism in between the child widgets. Use layoutsato createerror on the QHBox constructor, it means that you are using an older version of If you get compiler forms that automatically size and scale[*]

Qt. Make sure that you are using Qt 3.2.0 or a later Qt 3 release.

Create custom signals, slots, events, and controls Lines 12 and 13 create a QSpinBox and a QSlider with the QHBox as the parent. Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 424 1

Even though we didn't set the position or size of any widget explicitly, the QSpinBox and [ Team LiB ] QSlider appear nicely laid out side by side inside the QHBox. This is because QHBox automatically assigns reasonable positions and sizes to its children based on their needs. Qt provides many classes like QHBox to free us from the chore of hard-coding screen positions in our applications. Lines 14 and 15 set the valid range for the spin box and the slider. (We can safely assume that the user is at most 130 years old.) The two connect() calls shown in lines 16 to 19 ensure that the spin box and the slider are synchronized so that they always show the same value. Whenever the value of one widget changes, its valueChanged(int) signal is emitted, and the setValue(int) slot of the other widget is called with the new value. Line 20 sets the spin box value to 35. When this happens, the QSpinBox emits the valueChanged(int) signal with an int argument of 35. This argument is passed to the QSlider'ssetValue(int) slot, which sets the slider value to 35. The slider then emits the valueChanged(int) signal, because its own value changed, triggering the spin box's Table of Contents setValue(int) slot. But at this point, setValue(int) doesn't emit any signal, since the spin box value is Index already 35. This prevents infinite recursion. Figure 1.6 summarizes the situation.C++ GUI Programming with Qt 3 ByJasmin Blanchette , Mark Summerfield Figure 1.6. Changing

one value changes both

Publisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2 Pages: 464

"...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Line 22 shows the QHBox and its two child widgets. Straight from Trolltech, this book covers all you need to build industrial-strength applications Qt's approachandbuilding user interfaces run natively understand and very flexible. The X, and with Qt 3.2.x to C++-applications that is simple to on Windows, Linux/Unix, Mac OS most common pattern with no programmers use is toThe book teaches solid Qt programming embedded Linux that Qt source code changes! instantiate the required widgets and then set their properties as necessary. the documentation. You'll find to layouts, which automatically practices; it is not a rehash of Programmers add the widgets start-to-finish coverage packed take care of sizing and positioning. User interface behavior is C++ compilers-including a nonwith examples, plus a CD with the Qt 3.2 toolset and Borland managed by connecting widgets together using 3.2 signals and available nowhere commercial Qt Qt'sfor Windows slots mechanism. else! [ Team LiB ] Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 425 1

[ Team LiB ]

Using the Reference DocumentationQt's reference documentation is an essential tool for any Qt developer, since it covers every class and function in Qt. (Qt 3.2 includes over 400 public classes and over 6000 functions.) This book makes use of many Qt classes and functions, but it doesn't mention them all, nor does it provide all the details of those it does mention. To get the most benefit from Qt, you should familiarize yourself with the Qt reference documentation.

Widget Styles Contents Table ofIndex

C++ GUI Programming with Qtseen The screenshots we have 3

so far have been taken on Windows XP, but Qt applications look ,Mark Summerfield supported platform. Qt achieves this by emulating native on every ByJasmin Blanchette the platform's look and feel, rather than wrapping a particular platform or toolkit's widget set.Publisher: Prentice Hall PTR

Figure Pub Date: January 15, 2004 1.7.ISBN: 0-13-124072-2 Pages: 464

Styles available everywhere

"...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and Qt application users can override the default style by using the style commandembedded Linuxexample,source code changes! The book teaches solidstyle on Unix, line option. For with no to launch the Age application with Platinum Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed simply type with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! ./age -style=Platinum Build powerful C++ GUI applications quickly and easily on the command line. Design dialogs and main windows visually and in code

Figure 1.8. Platform-specific styles Learn Qt's innovative typesafe signals and slots mechanismUse layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 426 1

[ Team LiB ]

Unlike the other styles, the Windows XP and Mac styles are only available on their native platforms, since they rely on the platforms' theme engines.

The documentation is available in HTML format in Qt's doc\html directory and can be read using any web browser. You can also use Qt Assistant, the Qt help browser, whose powerful search and indexing features make it quicker and easier to use than a web browser. To launch Qt Assistant, click Qt 3.2.x|Qt Assistant in the Start menu on Windows, type assistant on the Table Unix, or double-click assistant in the Mac OS X Finder. command line on of Contents IndexC++ GUI Programming with Qt 3

Figure 1.9. Qt's documentation in Qt Assistant

ByJasmin Blanchette , Mark Summerfield

Publisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2 Pages: 464

"...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and The links inLinux withReference" section on the home page provide different ways of navigating embedded the "API no source code changes! The book teaches solid Qt programming Qt's classes. The "All Classes" the documentation. You'll find start-to-finish coverage packed practices; it is not a rehash of page lists every class in Qt's API. The "Main Classes" page lists only the most commonly with the Qt 3.2 As an and Borland might want to look up the with examples, plus a CDused Qt classes.toolsetexercise, you C++ compilers-including a nonclasses and Qt 3.2 for Windows available nowhere else! commercial functions that we have used in this chapter. Note that inherited functions are documented in the base class; for example, QPushButton has no show() function of its own, but it inherits one from its ancestor QWidget.Figure 1.10 shows how the classes we have seen so farBuild powerful C++ GUI applications quickly and easily relate to each other. Design dialogs and main windows visually and in code

Figure 1.10. Inheritance tree for the Qt classes seen so far

Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 427 1

[ Team LiB ]

The reference documentation for the current version of Qt and for some earlier versions is available online at http://doc.trolltech.com/. This site also hosts selected articles from Qt Quarterly, the Qt programmers' newsletter sent to all commercial licensees. [ Team LiB ] Table of Contents Index

C++ GUI Programming with Qt 3 ByJasmin Blanchette , Mark Summerfield

Publisher: Prentice Hall PTR Pub Date: January 15, 2004 ISBN: 0-13-124072-2 Pages: 464

"...not only the best book on Qt I have ever seen, but also the best book presenting any programming framework. Every sentence appears to be carefully worded, and every chapter has a sound concept, and so does the work as a whole." -Matthias Ettrich, Trolltech's lead developer, founder of the KDE project "The 'Tao of Qt'.... The Qt system is a beautiful example of object oriented design, and the authors take advantage of this.... The authors have done an excellent job of presenting the subject in an interesting and engaging way...." -Ron McCarty, Instructor and Chair of the Department of Computer Science, Penn State Erie, The Behrend College The first official Trolltech guide to Qt 3.2 programming! Straight from Trolltech, this book covers all you need to build industrial-strength applications with Qt 3.2.x and C++-applications that run natively on Windows, Linux/Unix, Mac OS X, and embedded Linux with no source code changes! The book teaches solid Qt programming practices; it is not a rehash of the documentation. You'll find start-to-finish coverage packed with examples, plus a CD with the Qt 3.2 toolset and Borland C++ compilers-including a noncommercial Qt 3.2 for Windows available nowhere else! Build powerful C++ GUI applications quickly and easily Design dialogs and main windows visually and in code Learn Qt's innovative typesafe signals and slots mechanism Use layouts to create forms that automatically size and scale Create custom signals, slots, events, and controls Program the ''Qt way'' with techniques for Qt 3.2 that'll work with Qt 428 1

[ Team LiB ]

Chapter 2. Creating DialogsSubclassing QDialog Signals and Slots in Depth Rapid Dialog Design Shape-C hanging Dialogs Table of Contents Dynamic Dialogs Index

C++ GUI Programming with Qt 3 Built-in Widget and Dialog

Classes

ByJasmin Blanchette , Mark Summerfield

This chapter will teach you how to create dialog boxes using Qt. They are called dialog boxes, or simply "dialogs", because they provide a means by which users and applications can "talk to" Publisher: Prentice Hall PTR each other.Pub DialogsDate: January 15, 2004 options and choices, and allow them to set the options to their present users with ISBN: 0-13-124072-2 preferred values and to make their choice. Most GUI applications consist of a main window with Pages: and a menu bar 464 toolbar, along with dozens of dialogs that complement the main window. It is also possible to create dialog applications that re