QT Programming QT Programming Seminar Seminar Date : Dec 22, 2001 Date : Dec 22, 2001 Time : 9:15AM – 12:15AM Time : 9:15AM – 12:15AM Venue : HSB 508, CUHK Venue : HSB 508, CUHK Speaker : Speaker : Alex Tsui Alex Tsui Dr. Y.S. Mo Dr. Y.S. Mo on on Sam Cheng Sam Cheng K.F. Fong K.F. Fong Eric Tang Eric Tang K.C. Chan K.C. Chan
38
Embed
QT Programming Seminar Date : Dec 22, 2001 Time : 9:15AM – 12:15AM Venue : HSB 508, CUHK Speaker : Alex Tsui Dr. Y.S. Moon Sam Cheng K.F. Fong Eric Tang.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
QT Programming SeminarQT Programming SeminarDate : Dec 22, 2001 Date : Dec 22, 2001
Trolltech ASTrolltech AS Founded in 1994Founded in 1994 Computer software companyComputer software company Provide software development Provide software development
tools, libraries and consulting tools, libraries and consulting servicesservices
First commercial Qt - 1995First commercial Qt - 1995
What is QtWhat is Qt
C++ toolkits for application C++ toolkits for application developmentdevelopment
Target all major OS with a single Target all major OS with a single application source codeapplication source code
Provide platform-independent Provide platform-independent APIAPI
Native C APIs are encapsulated Native C APIs are encapsulated with object-oriented C++ classeswith object-oriented C++ classes
Advantage of QtAdvantage of Qt
Can maintain same set of Can maintain same set of source code for multi-platformsource code for multi-platform Fast productivities on different Fast productivities on different
platformplatform Easy to maintain application Easy to maintain application
source codesource code Provide native look and feel for Provide native look and feel for
different platformdifferent platform
Qt/DesktopQt/Desktop
Qt/Windows for MS WindowsQt/Windows for MS Windows Qt/X11 for Linux, Solaris, HP-UX, IrQt/X11 for Linux, Solaris, HP-UX, Ir
ix, AIXix, AIX Qt/Mac Apple Mac OS XQt/Mac Apple Mac OS X
Qt/EmbeddedQt/Embedded
Designed for embedded device with Designed for embedded device with limited resourceslimited resources
Provide full GUI functionality without Provide full GUI functionality without X11X11
Reduce memory and CPU demand Reduce memory and CPU demand Can be scaled down for dedicated Can be scaled down for dedicated
systemsystem Fully compatible with Qt/DesktopFully compatible with Qt/Desktop
What is QPE/QtopiaWhat is QPE/Qtopia
Window environment designed fWindow environment designed for PDAsor PDAs
Based on libraries under Qt/EmBased on libraries under Qt/Embeddedbedded
Provide Personal Information MProvide Personal Information Management applicationsanagement applications Calendar, address book..etcCalendar, address book..etc
Web browser and Java support Web browser and Java support with third party developmentwith third party development
Method 1 – X11 simulationMethod 1 – X11 simulation Simulate QPE in X11 environmentSimulate QPE in X11 environment AdvantageAdvantage
Easy to control as we familiar to X11 environEasy to control as we familiar to X11 environmentment
Display card no need to have framebuffer suDisplay card no need to have framebuffer supportpport
DisadvantageDisadvantage Simulation may be inaccurate compare to thSimulation may be inaccurate compare to th
e final result in embedded devicee final result in embedded device Fonts may not be displayed correctly in embFonts may not be displayed correctly in emb
edded device as simulation use font library pedded device as simulation use font library provided from X11rovided from X11
Method 2 – framebuffer simulationMethod 2 – framebuffer simulation Directly use frambuffer device for simulaDirectly use frambuffer device for simula
tiontion AdvantageAdvantage
Can provide a accurate simulation compare tCan provide a accurate simulation compare to X11 o X11
DisadvantageDisadvantage Display card must support framebufferDisplay card must support framebuffer Keyboard and mouse devices may crash whKeyboard and mouse devices may crash wh
en return from framebuffer simulationen return from framebuffer simulation Need to restart keyboard/mouse driversNeed to restart keyboard/mouse drivers
Framebuffer simulationFramebuffer simulation
RequirementsRequirements PC with Linux OS (We use 7.1 here)PC with Linux OS (We use 7.1 here) Video card with framebuffer support Video card with framebuffer support
(usually only very old video card do n(usually only very old video card do not support it)ot support it)
Qt/X11 Qt/X11 Provide uic - user interface converterProvide uic - user interface converter UIC is used to convert Qt designer files to .cpp aUIC is used to convert Qt designer files to .cpp a
nd .h filesnd .h files Designer files are generated from designer tools Designer files are generated from designer tools
in Qt for designing the interface visuallyin Qt for designing the interface visually Qt/Embedded need “uic” for compiling the gui libQt/Embedded need “uic” for compiling the gui lib
rariesraries Qt/EmbeddedQt/Embedded
Provide Qt libraries for embedded devicesProvide Qt libraries for embedded devices QPE/QtopiaQPE/Qtopia
Provide a complete window manager with icons, Provide a complete window manager with icons, input methods and resource managementinput methods and resource management
Tools for add applicationsTools for add applications
tmaketmake A cross-platform Makefile ToolA cross-platform Makefile Tool For creating and maintaining makefiles For creating and maintaining makefiles
for software projectfor software project
DemosDemos
QPE Desktop SimulationQPE Desktop Simulation Add applications to QPEAdd applications to QPE QPE on embedded device - AssabetQPE on embedded device - Assabet
Qt DesignerQt Designer
A visual form designer for Qt providA visual form designer for Qt provided in Qt/x11ed in Qt/x11
Simple implementation and design of Simple implementation and design of user interfaces user interfaces
Allow to add actions and widgets (suAllow to add actions and widgets (such as button or tool bar) on the form ch as button or tool bar) on the form visuallyvisually
Qt DesignerQt Designer
Steps in creating a form with Qt DesignSteps in creating a form with Qt Designer and uicer and uic
1.1. Start the designer in Qt/X11Start the designer in Qt/X11
2.2. Add the necessary widgets in a form usinAdd the necessary widgets in a form using the designerg the designer
3.3. It will create a .ui fileIt will create a .ui file
4.4. Run uic to convert the .ui file to a .h file aRun uic to convert the .ui file to a .h file and .cpp file (implementation files)nd .cpp file (implementation files)
5.5. Create main.cpp to instantiate the QAppliCreate main.cpp to instantiate the QApplication object and start the event loopcation object and start the event loop
Qt DesignerQt Designer
Qt DesignerAdd widgets in a form form.ui
uicform.h
form.cppmain.cpp
#include#include
read & write
DemoDemo
Demonstration on using Qt Designer Demonstration on using Qt Designer and uicand uic
Qt 2.0 and later versions have full Qt 2.0 and later versions have full support for Unicode 16-bit support for Unicode 16-bit international character setinternational character set
It uses It uses UnicodeUnicode for text processing for text processing and string storageand string storage
Qt provides different text codec Qt provides different text codec classesclasses
It can display texts with different It can display texts with different encodings such as Big5 or GBencodings such as Big5 or GB
Display Chinese in QtDisplay Chinese in Qt
Steps in displaying Chinese text in QtSteps in displaying Chinese text in Qt
1.1. Create a text codec (Big5Codec or Create a text codec (Big5Codec or GBKCodec)GBKCodec)
2.2. Use the decoder to convert the ChiUse the decoder to convert the Chinese text to Unicodenese text to Unicode
3.3. Use “unifont” to display the stringUse “unifont” to display the string
Display Chinese in Qt Display Chinese in Qt (Example)(Example)QCString big5Str = “QCString big5Str = “ 歡迎光臨歡迎光臨”” ; ; // Chinese String// Chinese String
TrueType (TTF)TrueType (TTF) the scalable font technology on MS-Windows athe scalable font technology on MS-Windows a
nd Apple Macintoshnd Apple Macintosh
Postscript Type1 (PFA/PFB)Postscript Type1 (PFA/PFB) scalable fonts often used by printers, also populscalable fonts often used by printers, also popul
ar on X11ar on X11
Bitmap Distribution Format fonts (BDF)Bitmap Distribution Format fonts (BDF) a standard format for non-scalable fontsa standard format for non-scalable fonts
Qt Prerendered Font (QPF)Qt Prerendered Font (QPF) a light-weight non-scalable font format specific ta light-weight non-scalable font format specific t
o Qt/Embeddedo Qt/Embedded
DemosDemos
A text editor which can load and A text editor which can load and display different languagesdisplay different languages
Browsers in Qt/EmbeddedBrowsers in Qt/Embedded
There are 3 possible choices:There are 3 possible choices: Qt Mozilla Qt Mozilla (www.mozilla.org)(www.mozilla.org)
Opera Opera (www.opera.org)(www.opera.org)
Konqueror/Embedded – with better suppKonqueror/Embedded – with better support and easy to compile it ort and easy to compile it (www.konqueror.(www.konqueror.org/embedded.html)org/embedded.html)
Konqueror/EmbeddedKonqueror/Embedded
A special version of the KDE browserA special version of the KDE browser It can run on the Qt/Embedded platfoIt can run on the Qt/Embedded platfo
rm for embedded devicesrm for embedded devices Small and do not require X-window sSmall and do not require X-window s
ystemystem Support HTML4, CSS, SSL, JavascriSupport HTML4, CSS, SSL, Javascri
pt, Cookies and IPv6pt, Cookies and IPv6 Can be scaled down during configurCan be scaled down during configur
ation (disable SSL)ation (disable SSL)
Konqueror/EmbeddedKonqueror/Embedded
It can display web pages of different It can display web pages of different character sets such as Big5 or Utf-8character sets such as Big5 or Utf-8
Tricks in making Konq/E display pagTricks in making Konq/E display pages with different languages:es with different languages: Compile the Qt/Embedded library with diCompile the Qt/Embedded library with di
fferent encoding supportfferent encoding support Use “unifont” font to display the web pagUse “unifont” font to display the web pag
eses
DemoDemo
Compilation and configuration of the Compilation and configuration of the Konq/E with Qt/Embedded and QPE Konq/E with Qt/Embedded and QPE supportsupport
Built-in input method in QPEBuilt-in input method in QPE HandwritingHandwriting KeyboardKeyboard PickboardPickboard UnicodeUnicode
Input MethodInput Method
Chinese Input MethodChinese Input Method
Based on the keyboard implementatioBased on the keyboard implementation, which provides all the event handlinn, which provides all the event handlingsgs
Add the English string to Chinese charAdd the English string to Chinese character mappingacter mapping
e.g. onf -> e.g. onf -> 你 你 (0xa741)(0xa741) Match the input English string to the cMatch the input English string to the c
orresponding Chinese characterorresponding Chinese character Convert the Chinese Char to Unicode Convert the Chinese Char to Unicode
formatformat
DemoDemo
Inputting Big5 characters using ChanInputting Big5 characters using ChangJie in QPEgJie in QPE
Linux Device DriverLinux Device Driver
From 2.0 to 2.4 KernelFrom 2.0 to 2.4 Kernel
Linux Device Driver OverviewLinux Device Driver Overview(Simplified Version)(Simplified Version)
User ApplicationsUser Applications
KERNEL APIsKERNEL APIse.g. File Systems/Memory Systeme.g. File Systems/Memory System
Linux KERNEL
System calls
Linux Kernel ModulesLinux Kernel Modulese.g. Linux device driverse.g. Linux device drivers
Two most common types:Two most common types: Character Device (e.g. printer)Character Device (e.g. printer) Block Device (e.g. hard disk)Block Device (e.g. hard disk)
The differences:The differences: Block Device Block Device
Buffer for each block in this deviceBuffer for each block in this device Fast read/write of blocks.Fast read/write of blocks.
Character DeviceCharacter Device Sequence of bytesSequence of bytes
Implement simple character Implement simple character device driverdevice driver
Provide implementations for the Provide implementations for the user to access this device.user to access this device. E.g. read/write/ioctl.E.g. read/write/ioctl.
Register it to the kernel.Register it to the kernel. 2.4 kernel changed the file 2.4 kernel changed the file
In Desktop, we can use inb(), In Desktop, we can use inb(), outb to read/write parallel port outb to read/write parallel port (EPP mode)(EPP mode)
In Embedded Linux, we can use In Embedded Linux, we can use internal register ( directly access internal register ( directly access I/O pins ), software simulated I/O pins ), software simulated EPP mode.EPP mode.