Dr. Dobb's Journal - June 2008 - (Page 30) d06espen_p4ds 4/11/08 9:15 AM Page 30 Core Technology by Espen Riskedal Qt and Windows CE A cross-platform C++ framework for mobile devices Qt is a C++ application framework from Trolltech that lets you write native applications that Espen is a senior software engineer for Trolltech. He can be contacted at espenr@ trolltech.com. can be compiled cross-platform. This means that the source code only needs to be written once, yet support Linux, Windows CE/98/XP/Vista, Mac OS X, UNIX, and Embedded Linux. To deploy, you simply compile it for your target platform. One well-known application taking advantage of this kind of capability is Google Earth, which is available for Linux, Windows, and Mac OS X. Qt makes it easy for Google to maintain its code base and simultaneously support several platforms. When it comes to embedded operating systems, Qt is supported by embedded Linux and, with the beta release of Qt 4.4, it supports Windows CE 5.0/6.0, and Windows Mobile 5.0/6.0. In this article, I create native applications for Windows CE using Qt. Windows CE targets different segments of the embedded marketplace. Windows Mobile, for instance, targets Smartphones and Pocket PCs. Windows Mobile has a specialized UI, and provides lightweight office and communication applications. Nevertheless, it’s still Windows CE. Generally speaking, when I refer to Windows CE, I include Windows Mobile and any other Windows CE flavor that supports the Windows CE Standard SDK 5.0 (or later). Qt comes with a UI builder tool for designing UIs. You can, of course, code the GUI by hand, but you can save time doing it in Qt Designer instead. Qt Designer stores the UI in an XML file, which generates C++ code that you can include in your project. Figure 2 shows the Qt Designer with the .ui file for Image Viewer. For this application, I use the QLabel, QLineEdit, and QPushButton widgets (controls). I use QLabel for the actual images and for textual information (such as the name of the current image and its dimensions). I use QLineEdit to display the name of the current directory, and QPushButton for user interactions in the application. Giving the widgets sensible names like previousImage, nextButton, and currentDirectory, it is simpler later on when using these widgets in the application code. Once you define the UI, you combine it with the application code. The generated C++ code created from the .ui file in Figure 2 results in a header file called ui_imageviewer.h. To use it, just include it in the code. Here, I subclass a QWidget and initialize the GUI in the constructor: class PreviewWindow : public QWidget { Q_OBJECT public: An Image Viewer Example To demonstrate how you can use Qt, I present an image viewer called “Qt Image Viewer” (Figure 1) and internationalize it for three different languages. It has its own custom look-and-feel—and users can change both the language and look-and-feel while the application is running. The complete source code for the application is available online; see “Resource Center,” page 5. 30 Dr. Dobb’s Journal l www.ddj.com l June 2008 http://www.ddj.com
Table of Contents Feed for the Digital Edition of Dr. Dobb's Journal - June 2008 Dr. Dobb's Journal - June 2008 Contents Friday Night Fish Fry Alia Vox Developer Diaries There Must Be Contest Conversations Building a Test Harness for RTOS QT and Windows CE Software to Hardware Parallelization Performance Portable C++ Effective Concurrency The Agile Edge Swaine's Flames Dr. Dobb's Journal - June 2008 Dr. Dobb's Journal - June 2008 - Dr. Dobb's Journal - June 2008 (Page Cover1) Dr. Dobb's Journal - June 2008 - Dr. Dobb's Journal - June 2008 (Page Cover2) Dr. Dobb's Journal - June 2008 - Dr. Dobb's Journal - June 2008 (Page 1) Dr. Dobb's Journal - June 2008 - Dr. Dobb's Journal - June 2008 (Page 2) Dr. Dobb's Journal - June 2008 - Dr. Dobb's Journal - June 2008 (Page 3) Dr. Dobb's Journal - June 2008 - Contents (Page 4) Dr. Dobb's Journal - June 2008 - Contents (Page 5) Dr. Dobb's Journal - June 2008 - Friday Night Fish Fry (Page 6) Dr. Dobb's Journal - June 2008 - Friday Night Fish Fry (Page 7) Dr. Dobb's Journal - June 2008 - Friday Night Fish Fry (Page 8) Dr. Dobb's Journal - June 2008 - Friday Night Fish Fry (Page 9) Dr. Dobb's Journal - June 2008 - Alia Vox (Page 10) Dr. Dobb's Journal - June 2008 - Alia Vox (Page 11) Dr. Dobb's Journal - June 2008 - Alia Vox (Page 12) Dr. Dobb's Journal - June 2008 - Alia Vox (Page 13) Dr. Dobb's Journal - June 2008 - Developer Diaries (Page 14) Dr. Dobb's Journal - June 2008 - Developer Diaries (Page 15) Dr. Dobb's Journal - June 2008 - There Must Be Contest (Page 16) Dr. Dobb's Journal - June 2008 - There Must Be Contest (Page 17) Dr. Dobb's Journal - June 2008 - There Must Be Contest (Page 18) Dr. Dobb's Journal - June 2008 - There Must Be Contest (Page 19) Dr. Dobb's Journal - June 2008 - Conversations (Page 20) Dr. Dobb's Journal - June 2008 - Conversations (Page 21) Dr. Dobb's Journal - June 2008 - Building a Test Harness for RTOS (Page 22) Dr. Dobb's Journal - June 2008 - Building a Test Harness for RTOS (Page 23) Dr. Dobb's Journal - June 2008 - Building a Test Harness for RTOS (Page 24) Dr. Dobb's Journal - June 2008 - Building a Test Harness for RTOS (Page IBM-1) Dr. Dobb's Journal - June 2008 - Building a Test Harness for RTOS (Page IMB-2) Dr. Dobb's Journal - June 2008 - Building a Test Harness for RTOS (Page 25) Dr. Dobb's Journal - June 2008 - Building a Test Harness for RTOS (Page 26) Dr. Dobb's Journal - June 2008 - Building a Test Harness for RTOS (Page 27) Dr. Dobb's Journal - June 2008 - Building a Test Harness for RTOS (Page 28) Dr. Dobb's Journal - June 2008 - Building a Test Harness for RTOS (Page 29) Dr. Dobb's Journal - June 2008 - QT and Windows CE (Page 30) Dr. Dobb's Journal - June 2008 - QT and Windows CE (Page 31) Dr. Dobb's Journal - June 2008 - QT and Windows CE (Page 32) Dr. Dobb's Journal - June 2008 - QT and Windows CE (Page 33) Dr. Dobb's Journal - June 2008 - QT and Windows CE (Page 34) Dr. Dobb's Journal - June 2008 - QT and Windows CE (Page 35) Dr. Dobb's Journal - June 2008 - Software to Hardware Parallelization (Page 36) Dr. Dobb's Journal - June 2008 - Software to Hardware Parallelization (Page 37) Dr. Dobb's Journal - June 2008 - Software to Hardware Parallelization (Page 38) Dr. Dobb's Journal - June 2008 - Software to Hardware Parallelization (Page 39) Dr. Dobb's Journal - June 2008 - Performance Portable C++ (Page 40) Dr. Dobb's Journal - June 2008 - Performance Portable C++ (Page 41) Dr. Dobb's Journal - June 2008 - Performance Portable C++ (Page 42) Dr. Dobb's Journal - June 2008 - Performance Portable C++ (Page 43) Dr. Dobb's Journal - June 2008 - Performance Portable C++ (Page 44) Dr. Dobb's Journal - June 2008 - Performance Portable C++ (Page 45) Dr. Dobb's Journal - June 2008 - Performance Portable C++ (Page 46) Dr. Dobb's Journal - June 2008 - Performance Portable C++ (Page 47) Dr. Dobb's Journal - June 2008 - Effective Concurrency (Page 48) Dr. Dobb's Journal - June 2008 - Effective Concurrency (Page 49) Dr. Dobb's Journal - June 2008 - Effective Concurrency (Page 50) Dr. Dobb's Journal - June 2008 - Effective Concurrency (Page 51) Dr. Dobb's Journal - June 2008 - The Agile Edge (Page 52) Dr. Dobb's Journal - June 2008 - The Agile Edge (Page 53) Dr. Dobb's Journal - June 2008 - The Agile Edge (Page 54) Dr. Dobb's Journal - June 2008 - The Agile Edge (Page 55) Dr. Dobb's Journal - June 2008 - Swaine's Flames (Page 56) Dr. Dobb's Journal - June 2008 - Swaine's Flames (Page Cover3) Dr. Dobb's Journal - June 2008 - Swaine's Flames (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.