QT Programming Seminar Date : Dec 22, 2001 Time : 9:15AM – 12:15AM Venue : HSB 508, CUHK Speaker :...

38
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
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    214
  • download

    0

Transcript of QT Programming Seminar Date : Dec 22, 2001 Time : 9:15AM – 12:15AM Venue : HSB 508, CUHK Speaker :...

QT Programming SeminarQT Programming SeminarDate : Dec 22, 2001 Date : Dec 22, 2001

Time : 9:15AM – 12:15AMTime : 9:15AM – 12:15AM

Venue : HSB 508, CUHKVenue : HSB 508, CUHK

Speaker : Speaker : Alex TsuiAlex TsuiDr. Y.S. MoonDr. Y.S. Moon

Sam ChengSam Cheng

K.F. FongK.F. Fong

Eric TangEric Tang

K.C. ChanK.C. Chan

HistoryHistory

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

QPE Desktop Simulation (1)QPE Desktop Simulation (1)

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

QPE Desktop Simulation (2)QPE Desktop Simulation (2)

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)

Tools neededTools needed Qt/X11Qt/X11 Qt/Embedded Qt/Embedded QPE/QtopiaQPE/Qtopia tmaketmake

Tools for simulationTools for simulation

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

Online Reference:Online Reference:

http://doc.trolltech.com/3.0/designer-manual-8.htmlhttp://doc.trolltech.com/3.0/designer-manual-8.html

Text ProcessingText Processing

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

// Create big5 codec// Create big5 codec

QTextCodec *big5Codec = QTextCodec::codecForNameQTextCodec *big5Codec = QTextCodec::codecForName(“Big5”); (“Big5”);

QTextDecoder *big5Decoder = big5Codec->makeDecodeQTextDecoder *big5Decoder = big5Codec->makeDecoder();r();

// Convert Chinese text to Unicode format// Convert Chinese text to Unicode format

QString big5UnicodeStr = big5Decoder->toUnicode(big5QString big5UnicodeStr = big5Decoder->toUnicode(big5Str.data(), big5Str.length()); Str.data(), big5Str.length());

// Set display font// Set display font

QFont unifont(“unifont”, 16, 50); unifont.setPixelSizeQFont unifont(“unifont”, 16, 50); unifont.setPixelSize(16);(16);

Font Formats in QtFont Formats in Qt

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

Hardware DevicesHardware Devicese.g. CPU/Memory/IO ports.e.g. CPU/Memory/IO ports.

Linux Device DriverLinux Device Driver

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

Module architecture:Module architecture: Init_module()Init_module()

Initialize this kernel moduleInitialize this kernel module Register this module to the kernelRegister this module to the kernel

Exit_module()Exit_module() Cleanup all the memories.Cleanup all the memories. Unregister it.Unregister it.

From 2.0 to 2.4From 2.0 to 2.4 Provide module_init() & module_exit() to Provide module_init() & module_exit() to

specify the init/exit functions specify the init/exit functions

Implement file OperationsImplement file Operations

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

operations/ inode operations.operations/ inode operations.

File Operations 2.4File Operations 2.4

File operations :File operations :

Owner /* new */Owner /* new */ lseeklseek readread writewrite readdirreaddir pollpoll ioctlioctl mmapmmap openopen flushflush releaserelease fsyncfsync fasyncfasync locklock Readv /* new */Readv /* new */ Writev /* new */Writev /* new */

Port from 2.0 to 2.4Port from 2.0 to 2.4

use gcc labeled elements use gcc labeled elements extension for initialize the fopsextension for initialize the fops

E.g.E.g.struct file_operations{struct file_operations{

read: device_read,read: device_read,

write: device_write,write: device_write,

open: device_open,open: device_open,

release: device_closerelease: device_close

}} Avoid ordering problems of the elements in fops.Avoid ordering problems of the elements in fops.

Infineon FingerTIP Driver Infineon FingerTIP Driver

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.

Thank Thank You!You!