嵌入式学习之QT学习---14 QT跨平台运行之把QT程序交叉编译到ARM开发板
想要把qt工程放到開發板上運行,就需要用到交叉編譯。由于qt是跨平臺的,所以只需要換個編譯器編譯一下就可以。
以qt學習–計時器的例子為例,在移植之前還需要進行一個準備工作,在windows下運行的時候,電腦屏幕很大,但是運行的窗口只有一點點大,開發板也有外接屏幕,如何讓運行窗口自動適配開發板的外接屏幕呢?令其占滿屏幕顯示,而不是一小塊。
一、編譯生成在開發板上的可執行文件
第一步:需要設置一下,先給ui布局,如果不布局,控件就不會隨著屏幕的大小的變化而變化。利用代碼來獲取屏幕的大小,給widget.cpp文件下添加如下代碼
#include <QDesktopWidget> #include <QStyle> #include <QRect> 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),可以使得界面更美觀。
第二步:用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_systemroot@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.uiroot@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 ”路徑下。
按道理執行完這條路徑指令之后應該沒有任何提示的,刪除生成的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# makeroot@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,如果報錯
解決辦法:執行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 ARGSRun 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終于可以在開發板上跑程序啦,哭遼,經歷了兩天左右的時間呢。給大家淺看一下在開發板上運行的圖片。
總結
以上是生活随笔為你收集整理的嵌入式学习之QT学习---14 QT跨平台运行之把QT程序交叉编译到ARM开发板的全部內容,希望文章能夠幫你解決所遇到的問題。