【Qt】Ubuntu下Qt应用程序自启动设置

1、问题描述

第一步,确保手动启动Qt程序没有报错!如果报以下错误,参见博客

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.

第二步,在Ubuntu系统中设置自启动脚本,例如在 /etc/rc.local 文件中添加启动脚本,但是在自启动时报错:

*******XOpenDisplay Fail ******* 
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.

在第一步中已经确定根“xcb”库没关系,问题出在启动脚本上。

2、解决方法

如果在Qt程序中使用 Qt += gui,那么该程序应该在桌面系统gnome中启动,脚本因该添加在“~/.config/autostart”目录下,内容如下

[Desktop Entry]
Type=Application
Exec="~/test"
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_IN]=name
Name=程序名
Comment[en_IN]=comment
Comment=注释
3、参考规范

桌面应用程序自动启动规范:根据“XDG基本目录规范”制定

4、扩展

ubuntu使用图形界面程序gnome-session-properties来设置自启动,参见博客

你可能感兴趣的:(Qt,ubuntu)