This talk is an introduction to development of Qt applications for embedded devices running Windows CE. We will show how to build Qt for your device and you will learn how to create your Qt programs on Desktop Windows and cross-compile it for the target device.
Presentation by Jörg Bornemann held during Qt Developer Days 2009.
http://qt.nokia.com/developer/learning/elearning
2. Agenda
• Introduction to Windows CE
• How to build Qt for Windows CE
• Windows CE 5 memory model
• Ways to more memory
• Demonstration
3. What is Windows CE?
• OS for embedded devices
• not derived from desktop Windows
• monolithic kernel
• highly configurable using Platform Builder
• runs on x86, ARM, SH4 and MIPS
3
4. The world of Windows CE
• Windows CE 5.2
– Windows mobile 5, 6, 6.1, 6.5
• SmartPhone (standard)
• PocketPC (classic / professional)
• Windows CE 6.0 R2
– Microsoft Auto
– Windows mobile 7?
4
5. Desktop Windows vs. Windows CE
• UTF16 string representation
• No NTFS support → no file security model
• No file drives
• No current directory
• Only 32 processes
• Only 32 MB memory per process (CE < 6)
5
6. Desktop Windows vs. Windows CE
• Number of threads limited to system resources
– no more free memory → no more threads
• API is a Win32 API subset
– no *A functions
– no asynchronous file I/O or network
– incomplete standard C libs
6
7. Desktop Windows vs. Windows CE
• Situation gets better with Windows CE 6
– Up to 1 GB process memory
– More than 32K processes
– Improved system call performance
– New product name:
Windows embedded CE
7
8. What do you need for development?
• Visual Studio 2005 Standard or
Visual Studio 2008 Professional
• Windows CE SDK for your device
• Qt for Windows CE from qt.nokia.com
• Perl for using out-of-source builds
• Qt Visual Studio Add-in from qt.nokia.com
8
9. Development work flow
• Prototype on Desktop Windows
• Switch to a Windows CE Qt build
• Build, deploy and run
– Not everybody in the team needs a
Windows CE development environment.
9
10. How to build Qt for Windows CE?
• Use shadow builds.
C:Qt4.6.0qtsource
win32
wincewm60professional
wince50standard-x86
10
11. How to build Qt for Windows CE?
Open a Visual Studio command prompt.
Add C:Qt4.6.0wincewm60professionalbin to PATH.
cd C:Qt4.6.0wincewm60professional
.qtsourcesconfigure
-xplatform wincewm60professional-msvc2008
-signature mysignature.pfx
Creates Qt configuration and builds the host tools:
• qmake, moc, uic, rcc
• setcepaths / checksdk
• cetest (if Remote API is in INCLUDE, LIBS)
11
12. How to build Qt for Windows CE?
...only two steps left...
setcepaths wincewm60professional-msvc2008
nmake
12
13. Qt DLL sizes
Library sizes of Qt 4.5.2 on Windows mobile 6 professional:
Qt library Size in MB
QtCore4.dll 1.67 MB
QtGui4.dll 5.67 MB
QtNetwork4.dll 0.53 MB
QtWebKit4.dll 6.86 MB
qjpeg4.dll 0.12 MB
sum 14.85 MB
13
14. The Windows CE 5.0 memory model
Slot 63 Resource only DLLs • only 32 MB per slot
• Application stack & heap grow
large memory area
from slot's bottom
Slot 32 Process 32
• DLLs are loaded into process
slots top-down
... • DLLs are guaranteed to have
Slot 3
the same address in every slot
Process 2
Slot 2 Process 1
Slot 1 bundled DLLs
Slot 0 current process
14
15. The Windows CE 5.0 memory model
Bundled DLLs
Load address
for new DLLs
15
17. Ways to more Virtual Memory
• Reduce the DLL size
• Use static linking
• Load small DLLs first
• Switch to Windows mobile 6.1
17
18. Reducing Qt DLL sizes
• Exclude the features you don't need
• “feature” = set of classes (e.g.
GraphicsView)
• define QT_NO_FEATURENAME
configure -D QT_NO_FEATURENAME
• add this define to your application .pro file
DEFINES += QT_NO_FEATURENAME
• Tedious stuff! Is there no easier way to do
this?
18
20. Reducing Qt DLL sizes using qconfig
In your desktop Windows Qt build directory:
md toolsqconfig
cd toolsqconfig
qmake ......toolsqconfigqconfig.pro
nmake release
releaseqconfig.exe
20
21. Reducing Qt DLL sizes using qconfig
Good candiates for exclusion:
• Standard dialogs (color, font, input, wizard, …)
• Convenience widgets (QCalendarWidget, ...)
• Clipboard, drag and drop, shortcuts
• QtConcurrent, FTP, QSystemTrayIcon
• GraphicsView for QWidget only applications
• MDI
21
22. Reducing Qt DLL sizes using qconfig
• Open the features description file in
srccorelibglobalqfeatures.txt
• Unselect unwanted features
• Save the result in
srccorelibglobalqconfig-myfeatures.h
• Reconfigure Qt
configure -qconfig myfeatures ...
22
24. Accessing the Large Memory Area
• just 32 MB? Are you serious?
• there's more behind slot 32
• use memory mapped files
• use the VirtualAlloc API
24
25. Accessing the Large Memory Area
Using memory mapped files:
• acquire memory at 64 K boundaries
QFile memfile("myfile.bin");
memfile.open(QIODevice::ReadWrite);
memfile.resize(1024*1024*2);
uchar* buf = memfile.map(0, 1024*1024*2);
...
memfile.unmap(buf);
memfile.remove();
25
26. Accessing the Large Memory Area
Using VirtualAlloc:
• Reserve memory at 64 K boundaries or
commit reserved memory at 4 K
boundaries
void* ptrBase = VirtualAlloc(0, dwSize,
MEM_RESERVE, PAGE_NOACCESS);
buffer = VirtualAlloc(ptrBase, dwSize,
MEM_COMMIT, PAGE_READWRITE);
...
VirtualFree(ptr, dwSize, MEM_DECOMMIT);
VirtualFree(ptr, 0, MEM_RELEASE);
26