一,需求

Qt开发的GUI程序,部署到树莓派中,并设置开机自启。

二,步骤

1,制作启动脚本和停止脚本。

我们需要编写两个脚本,来启动和停止我们的应用。这里假设我们的应用名称为test。

#启动脚本
#!/usr/bin/env bash

#设置环境变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/test

cd /usr/test

#启动主程序
./test
#停止脚本
#!/usr/bin/env bash

ID=` ps -ef | grep test | grep -v grep | awk '{print $2}'`

for id in $ID
do
kill -9 $id
done

2,制作安装脚本

我们需要编写一个脚本用于安装qt打包后的程序,也就是整个文件夹。脚本的作用就是将文件夹拷贝到指定的位置。

比如我们的程序在test文件夹内,内部含有完整的Qt应用程序及依赖库,我们在同级目录下创建一个安装脚本 install.sh。

#!/usr/bin/env bash

Install_App() {
echo "installing test ..."
target=$1
if [ x$target == x'' ]; then
echo "please input parameter 1 for target path"
exit
fi

sudo /usr/test/stop.sh
sleep 1
if [ ! -d "$target" ]; then
sudo mkdir $target
fi
cp -a test/* $target/
#sudo chown -R root:root $target

}

if [ $UID -ne 0 ]; then
echo "Is not superuser,please use sudo "
exit
else
ROOT_PATH=/usr/test
Install_App $ROOT_PATH
echo "Install completed !"
reboot
fi

3,系统的设置

这里有两种方式。

(1),sudo vim /etc/xdg/lxsession/LXDE-pi/autostart

#@lxpanel --profile LXDE-pi
#@pcmanfm --desktop --profile LXDE-pi
#@xscreensaver -no-splash
@sudo /usr/test/start.sh

(2),

  1. 在/home/用户/.config下创建autostart 的文件夹
  2. 在 autostart 目录下新建my.desktop
  3. 编辑 my.desktop
[Desktop Entry]
Name=AICounter
Comment=AICounter
Exec=sudo /usr/test/start.sh
Terminal=false
MultipulArgs=false
Type=Application
Categories=Application;Development;
StartupNotify=ture

三,树莓派的一些配置

1,屏蔽开机警告

在/boot/config.txt末尾添加语句
avoid_warnings=2

2,修改欢迎界面

替换 /usr/share/plymouth/themes/pix/splash.png

3,更换软件源

sudo nano /etc/apt/sources.list
deb https://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free
sudo apt-get update

4,时间相关

1,关掉网络 时间同步服务  sudo systemctl stop systemd-timesyncd.service
2,启动网络 同步时间服务 sudo systemctl start systemd-timesyncd.service
3,时间同步服务 禁止自启 sudo systemctl disable systemd-timesyncd.service
4,开机自启 时间同步服务 sudo systemctl enable systemd-timesyncd.service
5,手动修改时间 sudo date -s "2021-10-31 20:18:00"
6,date 检查时间
7,修改时区:sudo dpkg-reconfigure tzdata 亚洲 上海

要想改时间,先要修改为正确的时区

5,pcf85063a时钟芯片

/boot/configini
dtparam=i2c_arm=on
dtparam=i2c_vc=on
dtoverlay=i2c-rtc,pcf85063a,i2c_csi_dsi

6,中文支持

sudo apt-get install scim-pinyin