开机自启动GUI的问题
在arm的linux上写了个开机自启GUI的脚本,自启动后,发现程序初始化的配置目录竟然在用户目录(/home/user),而不是在我的程序目录(/home/user/program),但是我进入程序目录后,手动执行发现初始化的目录位置都是正确的(即当前可执行程序的目录)。
但是在Qt程序中,所有的初始化目录自己都是用QDir::currentPath。搞了很久之后,巧合之下在自己电脑又查了下QDir文档,发现之前文档竟然没看全(arm的linux那边分辨率很低,Qt的IDE直接默认1920)。
[static] QString QDir::currentPath()
Returns the absolute path of the application’s current directory. The current directory is the last directory set with QDir::setCurrent() or, if that was never called, the directory at which this application was started at by the parent process.
发现如果没调用setCurrent(path),那么默认目录是父进程。
由于是自启动GUI,那么是依赖于桌面进程,所以默认目录指向了用户目录。
个人解决方案是在main.cpp里面,主窗口执行前添加一个setCurrent(“/home/user/program”)。