前言
Qt Creator远程部署程序到Linux开发板,按照文档都配置好以后,点击运行报如下错误。
09:55:40: Starting /opt/test1/bin/test1 on atk-dlrk3568-device...
qt.qpa.plugin: Could not find the Qt platform plugin "eglfs" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: linuxfb, minimal, offscreen, vnc, wayland-egl, wayland.
网上找了很多方法,都没有效果。
经测试,如下方法管用,记录一下。
一、现象
- 根据如下输出,可以确定程序已经编译通过,且已经拷贝到开发板中。到开发板中的确也能找程序。
09:55:40: Starting /opt/test1/bin/test1 on atk-dlrk3568-device...
- 开发板中程序可以运行,说明编译器没问题。
root@ATK-DLRK356X:/opt/test1/bin# ./test1
QStandardPaths: runtime directory '/var/run' is not a directory, but a symbolic link to a directory permissions 0755 owned by UID 0 GID 0
- 根据报错猜测是板子中没有
eglfs这个 plugin,但是Qt Creator默认使用eglfs.
Could not find the Qt platform plugin "eglfs" in ""
- 到开发板中查找Qt相关的库文件,可以看到的确没有eglfs,有其他6个(linuxfb, minimal, offscreen, vnc, wayland-egl, wayland.)。

- 查看开发板的
QT_QPA_PLATFORM环境变量是wayland,说明开发板默认使用的是wayland.

二、解决方法
- Qt Creator修改默认plugin为wayland,添加
QT_QPA_PLATFORM环境变量。

- 修改后编译,又报错:error: XDG_RUNTIME_DIR not set in the environment.

- 再添加
XDG_RUNTIME_DIR环境变量。值我试了两个,有一个不行
XDG_RUNTIME_DIR=/run/user/1000 # 失败
XDG_RUNTIME_DIR=/var/run/ #成功,这就是在开发板中直接跑提示的那个路径

- 最后的环境变量配置如下(注意:只添加红框中的内容即可,其他都是系统默认的,不用修改):

- 在点击绿色运行按钮,开发板屏幕上就有程序运行了。
总结:
- 系统环境变量批量编辑中添加如下内容:
QT_QPA_PLATFORM=wayland
XDG_RUNTIME_DIR=/var/run/


- 如果板子里直接运行程序还是报错,但是程序运行正常。那有可能是板子里的
XDG_RUNTIME_DIR的值为/var/run,少了一个/,改为XDG_RUNTIME_DIR=/var/run/即可
export XDG_RUNTIME_DIR=/var/run/
- 或是直接修改设置这个环境变量的地方,例如我的板子是
/etc/profile.d/weston.sh中修改
文章讲述了在QtCreator中远程部署程序到Linux开发板时遇到的Qtplatformplugineglfs缺失问题,通过测试和修改默认插件及环境变量,最终找到解决方法。
8322

被折叠的 条评论
为什么被折叠?



