QT4编程实验指导硬件:博创经典2410L、PC机Pentumn500以上,硬盘80G以上。软件:PC机操作系统RHEL4+xshell+ARM-Linux开发环境qt-embedded-linux-opensource-src-4.4.0.tar.bz2tslib-1.4.tar.bz2、qt-x11-opensource-src-4.4.0.tar.gz一、编译QT-X11环境cd/home/sprifemkdirqt4cdqt4mkdirfor_pcmkdirfor_armcp/home/qt-x11-opensource-src-4.4.0.tar.gz/home/sprife/qt4/for_pccp/home/qt-embedded-linux-opensource-src-4.4.0.tar.bz2/home/sprife/qt4/for_armcp/home/tslib-1.4.tar.bz2/home/sprife/qt4/for_armcd/home/sprife/qt4/for_pctarxzvfqt-x11-opensource-src-4.4.0.tar.gzcdqt-x11-opensource-src-4.4.0./configure(./configure-prefix/usr/local/Trolltech/Qt-x11-4.4.0)(yes)gmakegmakeinstall二、编译QT/E环境注:核心板使用PXA270可略去触摸屏步骤使用USB鼠标作为输入1、编译tslib1.4触摸屏库cd/home/sprife/qt4/for_armtarxjvftslib-1.4.tar.bz2cdtslib-1.4vibuild.sh#/bin/shexportCC=arm-linux-gcc./autogen.shechoac_cv_func_malloc_0_nonnull=yesarm-linux.cache./configure--host=arm-linux--cache-file=arm-linux.cache-prefix=$PWD/../tslib1.4-installmakemakeinstall编译:./build.sh2、编译QT/E库cd/home/sprife/qt4/for_armtarxjvfqt-embedded-linux-opensource-src-4.4.0.tar.bz2cp-atslib1.4-install/lib/*qt-embedded-linux-opensource-src-4.4.0/lib/cp-atslib1.4-install/include/ts*qt-embedded-linux-opensource-src-4.4.0/include/cdqt-embedded-linux-opensource-src-4.4.0./configure-embeddedarm-xplatformqws/linux-arm-g++-depths16-little-endian-qt-mouse-linuxtp-qt-mouse-tslib-I/home/sprife/qt4/for_arm/tslib1.4-install/include–L/home/sprife/qt4/for_arm/tslib1.4-install/lib-prefix/mnt/nfs/Trolltech/qt-embedded-4.4.0makemakeinstall-prefix选项要特殊注意,该指定目录必须要与实际NFS目录对应否则字体处会出现错误3、测试触摸屏及QT/E程序1、建立NFS共享目录/arm2410clcd/mkdirarm2410clcdarm2410clmkdirTrolltechcdTrolltechmkdirqt-embedded-4.4.0cdqt-embedded-4.4.0cp/home/sprife/qt4/for_arm/qt-embedded-linux-opensource-src-4.4.0/lib/./-arfcp/home/sprife/qt4/for_arm/tslib1.4-install/etc/./-arfcp/home/sprife/qt4/for_arm/tslib1.4-install/bin/./-arf2、ARM端挂载NFS共享目录mount-onolock,rsize=4096,wsize=4096192.168.1.111:/arm2410cl/mnt/nfs3、设置环境变量cd/mnt/nfs/Trolltech/qt-embedded-4.4.0exportQTDIR=$PWDexportLD_LIBRARY_PATH=$PWD/libexportTSLIB_TSDEVICE=/dev/input/event0exportTSLIB_PLUGINDIR=$PWD/lib/tsexportTSLIB_CONSOLEDEVICE=noneexportTSLIB_CONFFILE=$PWD/etc/ts.confexportPOINTERCAL_FILE=$PWD/etc/ts-calib.confexportQWS_MOUSE_PROTO=tslib:/dev/input/event0exportTSLIB_CALIBFILE=$PWD/etc/ts-calib.confexportLANG=zh_CN4、执行触摸屏校准程序(在qt-embedded-4.4.0下)./bin/ts_calibrate如果出现如下错误提示:CouldntloadmodulepthresNorawmodulesloaded.ts_config:Success则更改ts.conf配置文件选择一个输入设备vi/mnt/nfs/Trolltech/qt-embedded-4.4.0/etc/ts.conf#Uncommentifyouwishtousethelinuxinputlayereventinterface#module_rawinput更改为#Uncommentifyouwishtousethelinuxinputlayereventinterfacemodule_rawinput若提示:/dev/touchscreen/ucb1x00:Nosuchfileordirectory则一般是环境变量没设置好的问题,可以重新仔细检查环境变量的设置再次执行触摸屏校准程序即可,程序会自动存储坐标校准信息以便应用程序使用。此时如无错误则进入5点触摸屏校准程序并存储配置文件还可以进行其他触摸屏测试程序ts_test、ts_print等5、执行QT/E带触摸屏的例子程序在宿主机端拷贝编译好的ARM端可执行程序cp/home/sprife/qt4/for_arm/qt-embedded-linux-opensource-src-4.4.0/examples/widgets/digitalclock/digitalclock/arm2410cl/Trolltech/qt-embedded-4.4.0/ARM端执行该程序./digitalclock–qws如出现如下错误:errorwhileloadingsharedlibraries:libz.so.1:cannotopensharedobjectfile:Nosuchfileordirectory则在宿主机端交叉编译器目录下搜索该库文件,拷贝到lib目录下(具体库文件位置可能不尽相同)cp/opt/host/armv4l/armv4l-unknown-linux/lib/libz.so.1/arm2410cl/Trolltech/qt-embedded-4.4.0/lib/若出现错误errorwhileloadingsharedlibraries:libstdc++.so.6:cannotopensharedobjectfile:Nosuchfileordirectory拷贝cp/home/bc/gcc-3.4.2-glibc-2.2.5/arm-linux/arm-linux/lib/libstdc++.so.6/arm2410cl/Trolltech/qt-embedded-4.4.0/lib/若errorwhileloadingsharedlibraries:libgcc_s.so.1:cannotopensharedobjectfile:Nosuchfileordirectory则cp/home/bc/gcc-3.4.2-glibc-2.2.5/arm-linux/arm-linux/lib/libgcc_s.so.1/arm2410cl/Trolltech/qt-embedded-4.4.0/lib/如果想让QT/E在ARM端支持USB鼠标,可以在ARM端配置环境变量2410核心板:exportQWS_MOUSE_PROTO=MouseMan:/dev/input/mouse0270核心板:exportQWS_MOUSE_PROTO=TPanel:/dev/touchpanelMouseMan:/dev/mice即可。三、编写QT-X11程序进入QTforX11目录中进行设计[root@vm-dev~]#cd/home/sprife/qt4/for_pc/建立实验目录[root@vm-devfor_pc]#mkdirtestqt-x11[root@vm-devfor_pc]#cdtestqt-x11/[root@vm-devtestqt-x11]#使用designer编辑程序控件[root@vm-devtestqt-x11]#/home/sprife/qt4/for_pc/qt-x11-opensource-src-4.4.0/bin/designer将弹出designer界面选择一个窗口布局Widget点击-创建拖拽几个简单的控件(TextEdit、PushBotton、TextLabel)进行界面设计初始化控件及相关属性内容建立信号与槽的连接show按钮与文本编辑框的连接clicked-clear第二组信号与槽的连接exit按钮与Form的连接clicked-closed退出界面编辑保存为UI格式testx11.ui[root@vm-devtestqt-x11]#/home/sprife/qt4/for_pc/qt-x11-opensource-src-4.4.0/bin/designer[root@vm-devtestqt-x11]#lstestx11.ui[root@vm-devtestqt-x11]#编辑main.cpp函数[root@vm-devtestqt-x11]#vimain.cpp#includeui_testx11.hintmain(intargc,char*argv[]){QApplicationapp(argc,argv);QWidget*widget=newQWidget;Ui::Formui;ui.setupUi(widget);widget-show();returnapp.exec();}[root@vm-devtestqt-x11]#lsmain.cpptestx11.ui[root@vm-devtestqt-x11]#编译程序生成工程文件.pro[root@vm-devtestqt-x11]#/home/sprife/qt4/for_pc/qt-x11-opensource-src-4.4.0/bin/qmake-project[root@vm-devtestqt-x11]#lstestqt-x11.protestx11.uimain.cpp编译生成Makefile文件[root@vm-devtestqt-x11]#/home/sprife/qt4/for_