遇到的错误如下:
Camera is created.
load vfvlog.[dll/so] failed for dll[/vfvlog.so] unexisted
LoadDbgConfig, LoadFile fail, err:-3, errno: No such file or directory
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb.
主要是第四行和第五行的错误,分别为找不到display图形用户界面和找不QT插件库,其主要原因就是在开机自启和定时器执行时无法加载全局变量,导致设置的全局变量失效,主要解决方式是在要执行的脚本中设置环境变量,具体解决方案如下:
将需要执行的脚本放到某个目录下,本项目放在了/root/Camera_Package目录下,执行的脚本如下:
#!/bin/sh
current_user=$(whoami)
echo "当前用户为:$current_user" >> /root/Camera_Package/Camera.log
#export QT_DEBUG_PLUGINS=1
#export QT_QPA_PLATFORM=xcb
export DISPLAY=192.168.2.188:0.0
export LD_LIBRARY_PATH=/root/Camera_Package/lib/:$LD_LIBRARY_PATH
export QT_QPA_PLATFORM_PLUGIN_PATH=/root/Camera_Package/plugins/platforms
if ! pgrep Camera > /dev/null; then
echo "Camera is not running. Starting Camera..."
cd /root/Camera_Package/
nohup ./Camera >> /root/Camera_Package/Camera.log 2>&1 &
echo "Camera is created." >> /root/Camera_Package/Camera.log
else
echo "Camera is running."
echo "Camera is running." >> /root/Camera_Package/Camera.log
fi
exit 0
a、注意要给脚本开可执行权限:chmod 777 corn-test.sh
b、本脚本内容中的export部分是指定环境变量,这是因为这部分不能放在全局变量中,在开机自启动脚本和定时器脚本中,是无法使用全局环境变量的,所以需要在当前执行脚本中指定变量路径。
其中DISPLAY变量是图形用户界面(GUI)应用程序变量,其对应的值为:hostname:display.screen分别代表主机名、显示号和屏幕号。例:export DISPLAY=192.168.2.188:0.0;
QT_QPA_PLATFORM_PLUGIN_PATH变量为QT库路径,改为自己的platform路径即可
/root/Camera_Package/corn-test.sh
第一次添加定时器时会出现一个选择编辑器的选项,选择vim basic即可
*/1 * * * * su - root -s /root/Camera_Package/corn-test.sh
在corn-test.sh脚本执行时,配置display对应的192.168.2.188电脑桌面会收到如下的提示,直接同意(是)即可。