QT Embedded for wince 学习笔记

经过几天的调试,终于在wince 5上面将QT程序跑起来了,由于是第一次玩CE,一切都不太顺利,下面将具体步骤纪录与下:

由于开发板有人在用,于是我就采用了模拟器的方式调试。处理器是ARM V4,所以搭建平台都是以这个为基础,需要准备以下东西
Windows CE Platform Builder 5,这个微软网站上有的下载,google一下便可,是120天评估版,功能上没有任何缩水。够用了,据说到期了重装即可,我还没到期,不知道 :) ,这个自然是用于生成wince系统的咚咚了,最后会生成一个nk.bin的文件。

另外你还需要安装Windows CE 5.0: Standard Software Development Kit (SDK)

http://www.microsoft.com/downloads/details.aspx?familyid=FA1A3D66-3F61-4DDC-9510-AE450E2318C3&displaylang=en

也是免费下载的。

在编译QT的时候也是要用到的。

还有就是准备QT了,最新的是QT Embedded 4.4,比以前的简单多了,就一个包,直接编译他就行

qt-embedded-wince-opensource-src-4.4.0.zip

http://trolltech.com/downloads/opensource

要编译QTE,你最好安装VC 2005,需要用它来编译QT,如何编译在QTE的包中有说明,只要注册对环境变量就没多大问题。稍微修改一下VC当中的vsvars32.bat添加一些你的QT路径就可以,比如bin,include所在目录,现configure,然后nmake即可,需要时间比较长 :)

另外当然需要一个BSP包,Device Emulator: ARMV4I BSP for Windows CE 5.0 给PB用的
微软网站上也提供了 DeviceEmulatorBSP
To use Windows CE Version 5.0 Sample ARM Device Emulator BSP, you need:
Windows CE 5.0 Platform Builder with ARMV4I support installed

https://ads.jiwire.com/JOS.aspx/http/www.microsoft.com/downloads/details.aspx?familyid=474B03A6-E87D-455D-BC16-B8CF18EF39B4&displaylang=en

安装好了PB & Device Emulator: ARMV4I BSP 就可以编译wince了,微软的东西用起来比较简单,有个向导,并且要添加什么模块的话,在左侧的目录树中添加即可。最后在release目录下会生成一个nk.bin,这个就是最后要烧录的文件了。

接下来就是要在win里用模拟器来跑wince了,可以在在pb里面跑,以前我写过相关的文章,可以参考,比较复杂。

http://www.00jijiao.com/blog/article.asp?id=237

方便的方法是我找了一个WindowsCEDeviceEmulatorLauncher的软件,绿色的,直接指定bin文件的路径和VC2005自带的设备仿真器地址即可(你安装了VC2005他会自动搜索),他还有一个叫主机共享的功能,很方便,模拟器启动起来以后会看到一个Storage card的盘,这就是你主机上你指定的目录。

这里可以下载

http://softbbs.it168.com/viewthread.php?tid=566807

配置好以后,点启动仿真器就可以运行wince了! :)

接下来就可以写wince的程序了。

这里建议安装一个 qt-vsintegration-1.3.1 ,可以在VC2005下方便建立QT的项目,当然它建立的是for win的QT程序,你需要在VC中配置成wince5 armv4i才行,具体的编译参数,可以参考前面编译的QT embedded包当中的example目录,随便找个例子,用VC 2005打开,参数照他配置就OK 了,有些参数是重要的,但比较容易遗漏。比如 C/C++ -> Command Line中的Additional options要添加-Zm200 -w34100 -w34189 -Zm200 -w34100 -w34189 -w34100 -w34189 在 Linker -> Command Line中添加/SUBSYSTEM:WINDOWSCE,5.00

/MACHINE:THUMB /SUBSYSTEM:WINDOWSCE,5.00 /MACHINE:THUMB 开始我忘记了,怎么也编译不成功!

下来就可以编译了,第一个wince5程序就诞生了 :)

下来把文件放到wince5下运行就可以了,用那个模拟器的主机共享盘即可,注意如果你编译的时候不是选的静态链接库,你需要拷贝相关的dll 其中有一个 msvcr80.dll比较难找,一开始一直在wince中无法运行,提示缺dll,后来才在不经意间找到,他在 你的VC安装目录
Microsoft Visual Studio 8\VC\ce\Dll\armv4i\ 当中,还有就是你QT Embedded \lib\目录下面的相关dll,其中QtCore4.dll QtGui4.dll肯定是必要的。如果你编译的是debug版本,要拷贝同名的后面带个d的dll,然后第一个wince程序就运行起来了

截图纪念 :)

Qt开发平台搭建

网上看了好多关于Qt开发平台搭建的帖子,但发现上面的帖子都比较旧,是针对Qt旧版本而写的。本人喜欢用较新版的东西,相信新版的东西肯定比旧版的东西好用,果不其然Qt的新版本真的很好用,而且搭建起来更加容易。刚开始接触的时候,Qt的众多版本搞的自己头昏脑涨,什么Qt/x11,Qt/win,Qt/embedded ,Qtopia core,Qtopia等等,真的是丈二和尚摸不着头脑,幸好有网络,上网总能找到自己想要的东西,而且又不需要给予别人回报,当然自己也有些责任共享自己的资料,看来共产主义在互联网已经开始萌芽了,哈哈。

先看看Qt的各个版本简介:

1.什么是QT

Qt是一个完整的C++应用程序开发框架。它包含一个类库,和用于跨平台开发及国际化的工具。Qt API在所有支持的平台上都是相同的,Qt工具在这些平台上的使用方式也一致, 因而Qt应用的开发和部署与平台无关。

2.什么是Qtopia

Qtopia是一个面向嵌入式Linux的全方位应用程序开发平台,同时也是用于基于Linux的PDA(个人数字助理),智能电话(Smartphone)以及其他移动设备的用户界面。简单地说,Qtopia实质上是一组关于PDA和智能电话的应用程序结合,如果需要开发这类产品可以在这组程序的基础上迅速构建出PDA或者智能电话。Qtopia实质上依赖Qt/Embedded。

3.什么是Qt/Embedded

Qt/Embedded是一个完整的自包含GUI和基于Linux的嵌入式平台开发工具。这个开发工具的名字好像最容易混淆,当然Qt/Embedded是最熟悉的名字,好像Qtopia Core说的也是它。最近,奇趣公司又该名字了,它的新名字叫做qt-embedded-linux-xxxx,看来这个Qt/Embedded的马甲还很多哈。

下面就是搭建Qt开发平台了,我的平台是fedora core 7,需要的Qt版本有两个:

qt-x11-opensource-src-4.3.2.tar.gz

qt-embedded-linux-opensource-src-4.4.0-rc1.tar.bz2

qt-x11版本可以产生Qt开发工具,如designer等等,最重要的是可以得到qvfb,嵌入式的开发有了qvfb,就可以不需要实际的开发板,也可以开发Qt应程序。qt-embedded版本就是专门用于嵌入式方面的版本。下面是安装步骤:

1. 解压这两个qt包

a) tar –jxvf qt-x11-opensource-src-4.3.2.tar.gz

b) tar –jxvf qt-embedded-linux-opensource-src-4.4.0-rc1.tar.bz2

c) cp qt-embedded-linux-opensource-src-4.4.0-rc1 qt-embedded-linux-opensource-src-4.4.0-rc1-x86

d) mv qt-embedded-linux-opensource-src-4.4.0-rc1 qt-embedded-linux-opensource-src-4.4.0-rc1-arm

这里,qt-embedded有两个复制:qt-embedded-linux-opensource-src-4.4.0-rc1-x86 和qt-embedded-linux-opensource-src-4.4.0-rc1-arm,根据他们的名字可以知道前者是适合x架构的,后者适合arm架构为什么需要两个呢?如果有开发板的话,可以只编译qt-embedded版本成arm架构的就可以了,但是很多时候用qvfb的话,开发会方便很多,所以多编译一个x86架构的也不错。这里是否有些疑问,qt-x11也是适合x86结构的,这不是和qt-embedded重复了吗?答案是这样的,qt-embedded版本只能在嵌入式板子上面运行,编译成x86架构的程序也只能在x86的嵌入式板子上跑。前面说过,我们需要qvfb来开发,但是qvfb只能执行x86架构的应用程序,所以需要让qt-embedded生成关于x86的库和其他文件。而将qt-embedded编译成arm,又是为什么呢?道理很简单,我最终的qt应用程序需要在arm架构上面运行,当然需要这方面的库,所以编译成arm也就顺理成章了。好了,现在简单的总结一下,首先,使用qt-x11提供的库和开发工具开发出qt应用程序,然后使用qt-embedded关于x86库和工具再次编译我们开发qt应用程序,这是所得到的可执行文件就可以在qvfb上运行了,最后,使用qt-embeddedd的arm库再次编译就可以得到在arm上能运行的可执行程序。很明显,如果有开发板,第二步是可要可不要的(最好是要),如果没有开发板的话,第三步也就没必要了,这样就不需要将qt-embedded编译成适合arm架构的。

2. 这一步当然就是编译了

a) qt-x11: ./configure -qvfb

make

cd tools/qvfb

make

cd ../..

make install

cp tools/qvfb/qvfb* /usr/local/Trolltech/Qt-4.3.2/bin

b) qt-embedded:

1) x86: ./configure

make

make install

2) arm: ./configure –arch arm

make

make install

OK,Qt嵌入式应用程序开发环境就搭建好了,比起前面的qt版本,新版本环境搭建明显简单了很多。

拖拽

拖拽文件到程序这个问题有了突破性进展,但不知为何取得了路径却无法加载。。。检查中。。
如果顺利的话,第二个alpha版马上会发布~

argc, *argv[]

以前一直不知道如何实现比如双击文本文件,打开notepad等文本编辑器,如何实现该文件的加载。
现在知道了。当你双击这个文件的时候,windows会给你一个argv的参数传给你。。这是一个你双击文件的路径信息,这样你就能实现双击文件你程序自动调用的功能了

举个例子 :
int main(int argc, char *argv[])
{
QStringList list;
while(*argv)
{
list.append((QString)*argv++);
}
Schneider w;
w.GetArgc(&list);
w.show();
}

win传给你两个参数。一个是你程序自己的路径,第二个就是你运行的那个文件的路径。

QT3 Visual C++ 2005 Express Edition Beta compiling

Requirements

Windows 2000 or XP
Microsoft Visual C++ 2005 Express Edition Beta
Platform SDK
Qt-3/Win Free sources

Installing “Microsoft Visual C++ 2005 Express Edition Beta” (MSVC8)

download the ISO image from lab.msdn.microsoft.com/express/maninstall/.
or install it online from lab.msdn.microsoft.com/express/visualc.

Installing the Platform SDK

Download all files (342 MB) from www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm
Extract the files as described and run “Setup.exe”: Install the “Core SDK”.
Get the Qt3/Win Free sources
by downloading a Qt-3 source snapshot from the KDE-Cygwin snapshot area.
or from the cvs repository:
first connect to the cvs server

C:\source> cvs -d :pserver:anonymous@cvs.sourceforge.net:/cvsroot/kde-cygwin loginenter empty password
then checkout the sources with
C:\source> cvs -z6 -d :pserver:anonymous@cvs.sourceforge.net:/cvsroot/kde-cygwin co -r QT_WIN32_3_3_BRANCH qt-3

Compiling Qt with command line tools

Open a cmd shell
Setup your compiler environment
“C:\source>C:\Programme\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat”Setup Qt environment (here sources in C:\source\qt-3, please adjust the path to your needs)
C:\source> set QTDIR=C:\source\qt-3
C:\source> set PATH=%QTDIR%\bin;%PATH%
C:\source> set QMAKESPEC=win32-msvc.netConfigure and build the source
The script first creates link_includes.exe and configure.exe which are needed for bootstrap the build process. link_includes copies all relevant Qt-headers into the include-directory. configure.exe is the replacement for the ./configure-script under Unix/Linux. After that, qmake.exe is build and the compilation gets started.
C:\source> cd C:\source\qt-3
C:\source\qt-3> configure.bat [-fast] [-verbose]configure knows some of the parameters of the x11 release configure script like -fast or -verbose.
For a full list see bin\configure.exe -help.

This should build the whole Qt release. If it breaks you can restart compiling with

C:\source\qt-3> nmake [< target >]for a list of all available targets see the toplevel Makefile

Start Qt applications
C:\source\qt-3> designer
C:\source\qt-3> assistant
C:\source\qt-3> linguist
C:\source\qt-3> cd tutorial\t1
C:\source\qt-3\tutorial\t1> t1

Compiling Qt with the IDE

Setup Qt environment in Arbeitsplatz/Eigenschaften/Umgebungsvariablen (german windows)
QTDIR=C:\source\qt-3
QMAKESPEC=win32-msvc.netand add C:\source\qt-3\bin to the PATH variable
Add the Platform SDK path (e.g. C:\Programme\Microsoft SDK\Include) at the end of the list to the options in
menu: Tools/Options: Projects and Solutions/VC++ Directories/Incude Files.

add also in “/Library Files” the library path (e.g. C:\Programme\Microsoft SDK\Lib)
run the configure.bat until it has builded the moc tool and stop it then
open and compile the C:\sources\qt-3\src\qt_mt.vcproj and qtmain.vcproj with the IDE
use other *.vcproj files

Notes

Do not use spaces in the qt source path, it will produce weired results
incremental link does not work
use static linkage for faster link processes
You don't have to download all the files – it is sufficent to go to http://www.microsoft.com/msdownload/platformsdk/sdkupdate and tell it to install the Core SDK (you have to use IE). So you don't have to fetch all of the 340 MB. Provided of course you trust Microsoft not to transfer whatever from your computer to somewhere else ;-)
The Beta has a Time bomb – it only a works 365 DAYS FROM THE DATE FIRST INSTALLED. This is in the License Agreement (they know why they put it there as nobody reads that – I only did because I wondered whether there actually was a time bomb…)
The eula says:
(b) Time Sensitive Prerelease Code
(i) PORTIONS OF THE SOFTWARE ARE DESIGNED TO CEASE FUNCTIONING ON MAY 1, 2006. OTHER PORTIONS OF THE SOFTWARE ARE DESIGNED TO CEASE FUNCTIONING 365 DAYS FROM THE DATE FIRST INSTALLED. NOTICE OF EXPIRATION WILL NOT BE GIVEN, SO RECIPIENT NEEDS TO PLAN FOR THE EXPIRATION DATE AND REMOVE RECIPIENT’S DATA PRIOR TO SUCH EXPIRATION. This Agreement may terminate prior to expiration of the time-sensitive portions of the SOFTWARE. A later expiration date does not extend the term of this Agreement or Recipient’s license under this Agreement.