qinyunti 发表于 2022-7-24 00:18

米尔MYC-YT507开发板测评:开发环境篇之三:Qt打坦克游戏

<h1><b>前言</b></h1>

<p style="">本文以一个Qt实现的喜闻乐见的打坦克游戏,来体验本开发板的Qt开发过程,主要从二次开发的角度,关注开发环境搭建的便捷性。</p>

<h1 style=""><b>准备</b></h1>

<p style="">参考《米尔MYC-YT507开发板测评:开发环境篇之一:Linux C按键控制LED》安装交叉编译环境。</p>

<p style="">以及基本的登录文件传输等操作。</p>

<h1 style=""><b>安装Qt开发环境</b></h1>

<h2 style=""><b>安装编译环境</b></h2>

<p style="">&nbsp;</p>

<p style="">windows下从http://down.myir-tech.com/MYD-YT507H/下载资料,其中03_Tools.zip解压</p>

<p style="">我这里解压后为E:\BOARD\MYC-YT507\03_Tools</p>

<p style="">将文件夹Complie Toolchain名字改为Complie_Toolchain因为linux中命令行文件名不能有空格。</p>

<p style="">&nbsp;</p>

<p style="">wsl中</p>

<p style="">cd ~</p>

<p style="">mkdir MYD-YT507H</p>

<p style="">cd MYD-YT507H/</p>

<p style="">&nbsp;</p>

<p style="">直接将windows下的文件解压到WSL中</p>

<p style="">tar -xvf /mnt/e/BOARD/MYC-YT507/03_Tools/Complie_Toolchain/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu-qt5.12.5-myir.tar.bz2 -C .</p>

<p style="">&nbsp;</p>

<p style="">&nbsp;</p>

<h2 style=""><b>安装 Qt Creator</b></h2>

<p style="">下载QtCreator</p>

<p style="">wget <a href="https://mirrors.tuna.tsinghua.edu.cn/qt/development_releases/qtcreator/5.0/5.0.0-rc1/qt-creator-opensource-linux-x86_64-5.0.0-rc1.run"><u>https://mirrors.tuna.tsinghua.edu.cn/qt/development_releases/qtcreator/5.0/5.0.0-rc1/qt-creator-opensource-linux-x86_64-5.0.0-rc1.run</u></a></p>

<p style="">&nbsp;</p>

<p style="">&nbsp;chmod +x qt-creator-opensource-linux-x86_64-5.0.0-rc1.run</p>

<p style="">&nbsp;</p>

<p style="">./qt-creator-opensource-linux-x86_64-5.0.0-rc1.run</p>

<p style="">需要实现注册账号</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp; &nbsp;</p>

<p style="">&nbsp;</p>

<p style="">运行/home/lhj/qtcreator-5.0.0-rc1/bin/qtcreator.sh &amp;</p>

<p style="">&nbsp;</p>

<h2 style=""><b>配置</b></h2>

<p style="">菜单栏点击 Tools -&gt; Options</p>

<p style="">&nbsp;</p>

<h3 style=""><b>配置编译器</b></h3>

<p style="">左边点击 Kits ,右边选择 Compilers标签</p>

<p style="">&nbsp;</p>

<p style="">添加G++编译器</p>

<p style=""> &nbsp;</p>

<p style="">设置Name为YT507H-G++</p>

<p style="">Compiler path为/home/lhj/MYD-YT507H/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++</p>

<p style="">点击&quot;Apply&quot;</p>

<p style="">&nbsp;</p>

<p style="">同样方式添加GCC编译器</p>

<p style="">设置Name为YT507H-GCC</p>

<p style="">Compiler path为</p>

<p style="">/home/lhj/MYD-YT507H/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc</p>

<p style="">&nbsp;</p>

<p style="">配置完后如下</p>

<p style=""> &nbsp;</p>

<p style="">&nbsp;</p>

<h3 style=""><b>配置Qmake</b></h3>

<p style="">选择&quot;Qt Version&quot;标签,在右侧点击&quot;Add...&quot;,会弹出 qmake 路径选择对话框</p>

<p style="">选择/home/lhj/MYD-YT507H/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/Qt_5.12.5/bin/qmake,点击Open</p>

<p style=""> &nbsp;</p>

<p style="">&quot;Version name&quot;改为 Qt %{Qt:Version} (MYIR-YT507H-System)。然后点击&quot;Apply&quot;按钮</p>

<p style=""> &nbsp;</p>

<h3 style=""><b>配置Device</b></h3>

<p style="">选择左侧&quot;Device&quot;,点击右边的&quot;Add...&quot;按钮,</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<h3 style=""><b>配置Kits</b></h3>

<p style="">左侧Kits,右侧Kits选项卡,点击Add</p>

<p style="">Name设置为YT507H-dev-kit</p>

<p style="">选择DeviceType</p>

<p style="">选择Device</p>

<p style="">选择Sysroot:/home/lhj/MYD-YT507H/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/Qt_5.12.5/aarch64-buildroot-linux-gnu/sysroot</p>

<p style="">Compiler选择刚才配置的C和C++编译器</p>

<p style="">Qt version选择Qt 5.12.5 (MYIR-YT507H- System)</p>

<p style="">&quot;Qt mkspec&quot;填写为&quot;linux-aarch64-gnu-g++&quot;</p>

<p style="">点击Apply</p>

<p style=""> &nbsp;</p>

<p style="">点击OK</p>

<p style="">&nbsp;</p>

<p style="">&nbsp;</p>

<h1 style=""><b>Tanks</b></h1>

<p style="">git clone <a href="https://github.com/qinyunti/tanks.git"><u>https://github.com/qinyunti/tanks.git</u></a></p>

<p style="">&nbsp;</p>

<p style="">打开QtCreator</p>

<p style="">/home/lhj/qtcreator-5.0.0-rc1/bin/qtcreator.sh &amp;</p>

<p style="">File-&gt; Open File or Project...选择刚clone的代码</p>

<p style=""> &nbsp;</p>

<p style="">选择YT507H-dev-kit</p>

<p style="">点击Configure Project</p>

<p style="">&nbsp;</p>

<p style=""> &nbsp;</p>

<p style="">&nbsp;</p>

<p style="">菜单栏</p>

<p style="">Build-&gt;Clean</p>

<p style="">Build-&gt;Build All Projects</p>

<p style="">&nbsp;</p>

<p style="">提示</p>

<p style=""> &nbsp;</p>

<p style="">&nbsp;</p>

<p style="">搜索find ../ -name libGLESv2.so</p>

<p style="">找到路径为</p>

<p style="">/home/lhj/MYD-YT507H/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/Qt_5.12.5/aarch64-buildroot-linux-gnu/sysroot/usr/lib/libGLESv2.so</p>

<p style="">&nbsp;</p>

<p style="">手动修改/home/lhj/MYD-YT507H/build-tanks-YT507H_dev_kit-Debug/Makefile如上红色框中的内容为/home/lhj/MYD-YT507H/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/Qt_5.12.5/aarch64-buildroot-linux-gnu/sysroot/usr/lib/libGLESv2.so</p>

<p style="">&nbsp;</p>

<p style="">&nbsp;</p>

<p style="">编译后的代码位于</p>

<p style="">&nbsp;</p>

<p style="">/home/lhj/MYD-YT507H/build-tanks-YT507H_dev_kit-Debug/Tanks</p>

<p style="">导出到Windows下</p>

<p style="">&nbsp;</p>

<p style="">&nbsp;cp /home/lhj/MYD-YT507H/build-tanks-YT507H_dev_kit-Debug/Tanks /mnt/e</p>

<p style="">再导入到开发板。</p>

<p style="">&nbsp;</p>

<h1 style=""><b>运行</b></h1>

<p style="">ps查看myapp2的进程号 kill掉</p>

<p style="">&nbsp;</p>

<p style="">export QT_DEBUG_PLUGINS=1 使能调式打印方便有问题分析</p>

<p style="">&nbsp;</p>

<p style="">./Tanks &nbsp;运行</p>

<p style="">&nbsp;</p>

<p style="">如果打印</p>

<p style="">./Tanks: error while loading shared libraries: libQt5Widgets.so.5: cannot open shared object file: No such file or directory</p>

<p style="">则:</p>

<p style=""><b>export LD_LIBRARY_PATH=/usr/local/Qt_5.12.5/lib/:$LD_LIBRARY_PATH</b></p>

<p style="">&nbsp;</p>

<p style="">&nbsp;</p>

<p style="">查看我们这里库路径是/usr/local/Qt_5.12.5/而程序中引用的是/usr/local/Qt-5.12.5/</p>

<p style="">所以创建软链接</p>

<p style="">ln -s /usr/local/Qt_5.12.5/plugins/platforms/ /root/platforms</p>

<p style="">ln -s /usr/local/Qt_5.12.5 /usr/local/Qt-5.12.5</p>

<p style="">&nbsp;</p>

<p style="">如果打印</p>

<p style="">loaded library &quot;/usr/local/Qt_5.12.5/plugins/egldeviceintegrations/libqeglfs-emu-integration.so&quot;</p>

<p style="">EGL library doesn&#39;t support Emulator extensions</p>

<p style="">Aborted</p>

<p style="">则</p>

<p style=""><b>export QT_QPA_EGLFS_INTEGRATION=none</b></p>

<p style="">&nbsp;</p>

<p style="">如果打印</p>

<p style="">QFontDatabase: Cannot find font directory /usr/local/Qt-5.12.5/lib/fonts.</p>

<p style="">则软链接到实际的字体文件处</p>

<p style="">ln -s /usr/local/Qt-5.12.5/fonts/ /usr/local/Qt-5.12.5/lib/fonts</p>

<p style="">&nbsp;</p>

<p style="">使用USB鼠标键盘控制</p>

<p style="">&nbsp;</p>

<p style="">按键</p>

<p style="">W:前进</p>

<p style="">S:后退</p>

<p style="">A:左转</p>

<p style="">D:右转</p>

<p style="">按键1,2,3分别选择火力,</p>

<p style="">按键q射击。</p>

<p style="">按键s暂停与继续</p>

<p style="">&nbsp;</p>

<p style=""> &nbsp;</p>

<p style=""> &nbsp;</p>

<h1 style=""><b>总结</b></h1>

<p style="">开发板支持Qt5.12,镜像中已安装了相应的运行环境。SDK也提供了工具链可以直接使用,所以开发是非常便捷的,相关文档也比较详细,对开发者比较友好。</p>

<p style="">&nbsp;</p>

<h1 style=""><b>参考</b></h1>

<p style="">MYD-YT507H_QT应用开发笔记.pdf</p>

Jacktang 发表于 2022-7-24 10:05

<p>开发板支持的功能很多,楼主介绍的也很详细</p>

lugl4313820 发表于 2022-7-24 10:55

我想安装pyqt,弄了好久也没有搞定!

freebsder 发表于 2022-7-28 15:54

<p>厉害,一直想学学游戏咋做的。。。</p>

nmg 发表于 2022-7-28 17:01

lugl4313820 发表于 2022-7-24 10:55
我想安装pyqt,弄了好久也没有搞定!

<p>缺包?可以把错误啥的百度,一般能搜到解决方案</p>

lugl4313820 发表于 2022-7-28 17:06

nmg 发表于 2022-7-28 17:01
缺包?可以把错误啥的百度,一般能搜到解决方案

<p>换成tkinter弄了</p>

<p>&nbsp;</p>

申小林 发表于 2022-8-17 08:35

<p>加油啊!!!!!!!!都是大神级别的</p>
页: [1]
查看完整版本: 米尔MYC-YT507开发板测评:开发环境篇之三:Qt打坦克游戏