嵌入式学习之QT学习---14 QT跨平台运行之把QT程序交叉编译到ARM开发板

想要把qt工程放到开发板上运行,就需要用到交叉编译。由于qt是跨平台的,所以只需要换个编译器编译一下就可以。
以qt学习–计时器的例子为例,在移植之前还需要进行一个准备工作,在windows下运行的时候,电脑屏幕很大,但是运行的窗口只有一点点大,开发板也有外接屏幕,如何让运行窗口自动适配开发板的外接屏幕呢?令其占满屏幕显示,而不是一小块。

一、编译生成在开发板上的可执行文件

第一步:需要设置一下,先给ui布局,如果不布局,控件就不会随着屏幕的大小的变化而变化。利用代码来获取屏幕的大小,给widget.cpp文件下添加如下代码

#include  
#include  
#include  

QDesktopWidget *deskTopWidget = QApplication::desktop(); 
QRect deskRect = deskTopWidget->availableGeometry(); 
int appH = deskRect.height(); 
int appW = deskRect.width(); 
this->setFixedSize(appW, appH); 
setGeometry(0, 0, appW, appH);

添加完后,编译运行一下,会看到现在运行结果显示框与电脑屏幕一样大。将layoutstrength处的(0,0,0)改成了(5,2,3),可以使得界面更美观。
嵌入式学习之QT学习---14 QT跨平台运行之把QT程序交叉编译到ARM开发板_第1张图片
嵌入式学习之QT学习---14 QT跨平台运行之把QT程序交叉编译到ARM开发板_第2张图片

第二步:用ssh软件把time文件夹传到ubuntu下

root@ubuntu:~# cd /home/qt/
root@ubuntu:/home/qt# ls
qt_source  qt_system
root@ubuntu:/home/qt# mkdir qt_demo
root@ubuntu:/home/qt# ls
qt_demo  qt_source  qt_system

root@ubuntu:/home/qt# cd qt_demo/
root@ubuntu:/home/qt/qt_demo# ls
time

第三步:删掉.pro.user文件,以免影响后面

root@ubuntu:/home/qt/qt_demo# cd time/
root@ubuntu:/home/qt/qt_demo/time# ls
main.cpp  time.pro  time.pro.user  widget.cpp  widget.h  widget.ui

root@ubuntu:/home/qt/qt_demo/time# rm time.pro.user 
root@ubuntu:/home/qt/qt_demo/time# 
root@ubuntu:/home/qt/qt_demo/time# ls
main.cpp  time.pro  widget.cpp  widget.h  widget.ui

第四步:执行make

root@ubuntu:/home/qt/qt_demo/time# make
make: *** 没有指明目标并且找不到 makefile。 停止。

显示找不到makefile,需要在命令行写上之前执行脚本文件并执行make以及make install的时候生成的文件的路径,我的在“/usr/local/Qt-5.7.0/bin/qmake ”路径下。
嵌入式学习之QT学习---14 QT跨平台运行之把QT程序交叉编译到ARM开发板_第3张图片

root@ubuntu:/home/qt/qt_demo/time# /usr/local/Qt-5.7.0/bin/qmake 
Info: creating stash file /home/qt/qt_demo/time/.qmake.stash

按道理执行完这条路径指令之后应该没有任何提示的,删除生成的makefile重新执行一下

root@ubuntu:/home/qt/qt_demo/time# ls
main.cpp  Makefile  time.pro  widget.cpp  widget.h  widget.ui
root@ubuntu:/home/qt/qt_demo/time# rm Makefile 
root@ubuntu:/home/qt/qt_demo/time# /usr/local/Qt-5.7.0/bin/qmake 
root@ubuntu:/home/qt/qt_demo/time# 
root@ubuntu:/home/qt/qt_demo/time# ls
main.cpp  Makefile  time.pro  widget.cpp  widget.h  widget.ui
root@ubuntu:/home/qt/qt_demo/time# make

root@ubuntu:/home/qt/qt_demo/time# ls
main.cpp  Makefile        moc_widget.o  time.pro     widget.cpp  widget.o
main.o    moc_widget.cpp  time          ui_widget.h  widget.h    widget.ui

生成time之后,在ubuntu界面再执行一条指令查看一下time的属性,看是否能够在开发板上运行。如果是属于ARM平台的二进制文件,则可以在开发板上执行;如果是x86-64,那就是x86上位机平台文件,不可以在开发板执行。
在这里插入图片描述

说明:
鉴于之前在开发板上烧写qt5.7未能成功,就选择使用早之前在开发板上可以运行的qt4.7版本了。

  • 针对qt4.7版本,其qmake文件所在路径为:/opt/qt-4.7.1/bin/qmake
  • 写完路径之后,执行make,如果报错
root@ubuntu:/home/qt/qt_demo/time# make
arm-linux-g++ -Wl,-O1 -Wl,-rpath,/opt/qt-4.7.1/lib -o time main.o widget.o moc_widget.o    -L/opt/qt-4.7.1/lib -lQtGui -L/usr/local/tslib/lib -L/opt/qt-4.7.1/lib -lQtNetwork -lQtCore -lpthread 
main.o: file not recognized: File format not recognized
collect2: ld returned 1 exit status
make: *** [time] 错误 1
root@ubuntu:/home/qt/qt_demo/time# ls
main.cpp  Makefile        moc_widget.o  ui_widget.h  widget.h  widget.ui
main.o    moc_widget.cpp  time.pro      widget.cpp   widget.o
root@ubuntu:/home/qt/qt_demo/time# rm Makefile 
root@ubuntu:/home/qt/qt_demo/time# /opt/qt-4.7.1/bin/qmake 
root@ubuntu:/home/qt/qt_demo/time# ls
main.cpp  Makefile        moc_widget.o  ui_widget.h  widget.h  widget.ui
main.o    moc_widget.cpp  time.pro      widget.cpp   widget.o
root@ubuntu:/home/qt/qt_demo/time# make
arm-linux-g++ -Wl,-O1 -Wl,-rpath,/opt/qt-4.7.1/lib -o time main.o widget.o moc_widget.o    -L/opt/qt-4.7.1/lib -lQtGui -L/usr/local/tslib/lib -L/opt/qt-4.7.1/lib -lQtNetwork -lQtCore -lpthread 
main.o: file not recognized: File format not recognized
collect2: ld returned 1 exit status
make: *** [time] 错误 1

解决办法:执行make clean命令,然后再执行make命令

root@ubuntu:/home/qt/qt_demo/time# make clean
rm -f moc_widget.cpp
rm -f ui_widget.h
rm -f main.o widget.o moc_widget.o
rm -f *~ core *.core
root@ubuntu:/home/qt/qt_demo/time# make
root@ubuntu:/home/qt/qt_demo/time# ls
main.cpp  Makefile        moc_widget.o  time.pro     widget.cpp  widget.o
main.o    moc_widget.cpp  time          ui_widget.h  widget.h    widget.ui
root@ubuntu:/home/qt/qt_demo/time# file time
time: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 2.6.14, not stripped

二、开发板上电启动qt系统,执行可执行文件

我选择的是用U盘拷贝可执行文件,然后在超级终端上挂载U盘,执行该可执行文件。

~ # ls /mnt/                                                                                                                                                                        
disk  usb1
~ # mount /dev/udisk /mnt/usb1/                                                                                                                                                     
~ # cd /mnt/usb1/                                                                                                                                                                   
/mnt/usb1 # ls
1.wav
myPhonon1
myPhonon11
python
scope_0.png
scope_1.png
scope_2.png
scope_3.png
t1110_success.slx
time

/mnt/usb1 # time -qws
time: invalid option -- 'q'
BusyBox v1.21.1 (2013-11-02 04:41:24 AMST) multi-call binary.

Usage: time [-v] PROG ARGS

Run PROG, display resource usage when it exits

        -v      Verbose

/mnt/usb1 # ./time                                                                                                                                                                  
[  240.998293] hub 1-0:1.0: port 3 disabled by hub (EMI?), re-enabling...
[  241.003575] usb 1-3: USB disconnect, device number 2
[  241.008424] usb 1-3.2: USB disconnect, device number 3
[  241.019297] dm9620 1-3.2:1.0: eth0: unregister 'dm9620' usb-s5p-ehci-3.2, Davicom DM9620 USB Ethernet
[  241.027855] mmc_sd_detect(mmc1): Unable to re-detect card (-123)
[  241.033468] mmc1: card 0001 removed
[  241.115188] dm9620_unbind():
[  241.116630] flg_txdbg  0
[  241.119149] rx_length_errors 0
[  241.125103] rx_over_errors   0
[  241.126708] rx_crc_errors    0
[  241.129745] rx_frame_errors  0
[  241.230112] rx_fifo_errors   0
[  241.231719] rx_missed_errors 0
[  241.310260] usb 1-3.3: USB disconnect, device number 4
[  241.830040] usb 1-3: new high speed USB device number 5 using s5p-ehci
[  241.901373] s5p-ehci s5p-ehci: port 3 reset error -110
[  242.576434] s5p-ehci s5p-ehci: port 3 reset error -110
[  242.850140] *******mmc1: inserted!!!!!******
[  242.939305] mmc1: new high speed SDHC card at address 0001
[  242.955253] mmcblk1: mmc1:0001 SD16G 14.5 GiB 
[  242.961626]  mmcblk1: p1 p2 p3 p4
[  243.196451] s5p-ehci s5p-ehci: port 3 reset error -110
[  243.816889] s5p-ehci s5p-ehci: port 3 reset error -110
[  244.436869] s5p-ehci s5p-ehci: port 3 reset error -110
[  244.850336] hub 1-0:1.0: Cannot enable port 3.  Maybe the USB cable is bad?
[  244.911890] s5p-ehci s5p-ehci: port 3 reset error -110
[  245.586859] s5p-ehci s5p-ehci: port 3 reset error -110
[  246.206867] s5p-ehci s5p-ehci: port 3 reset error -110
[  246.826865] s5p-ehci s5p-ehci: port 3 reset error -110
[  247.446869] s5p-ehci s5p-ehci: port 3 reset error -110
[  247.860332] hub 1-0:1.0: Cannot enable port 3.  Maybe the USB cable is bad?
[  247.921888] s5p-ehci s5p-ehci: port 3 reset error -110
[  248.596869] s5p-ehci s5p-ehci: port 3 reset error -110
[  249.216888] s5p-ehci s5p-ehci: port 3 reset error -110
[  249.836890] s5p-ehci s5p-ehci: port 3 reset error -110
[  250.456890] s5p-ehci s5p-ehci: port 3 reset error -110
[  250.870335] hub 1-0:1.0: Cannot enable port 3.  Maybe the USB cable is bad?
[  250.931868] s5p-ehci s5p-ehci: port 3 reset error -110
[  251.606868] s5p-ehci s5p-ehci: port 3 reset error -110
[  252.226889] s5p-ehci s5p-ehci: port 3 reset error -110
[  252.846890] s5p-ehci s5p-ehci: port 3 reset error -110
[  253.466892] s5p-ehci s5p-ehci: port 3 reset error -110
[  253.880497] hub 1-0:1.0: Cannot enable port 3.  Maybe the USB cable is bad?
[  253.886133] hub 1-0:1.0: unable to enumerate USB device on port 3

终于可以在开发板上跑程序啦,哭辽,经历了两天左右的时间呢。给大家浅看一下在开发板上运行的图片。

你可能感兴趣的:(ITOP4412学习,QT,qt,arm开发)