当前位置: 移动技术网 > 科技>操作系统>Linux > QT获取linux下的当年用户名

QT获取linux下的当年用户名

2019年12月05日  | 移动技术网科技  | 我要评论

故事背景:客户端启动的时候需要加载机器/home/xx/test.jpg的图片作为背景图,但是有的机器用户名叫aaa,有的机器名叫bbb,所以我需要获取当前用户的home目录

技术调研:qstandardpaths

    qstring strimagepath = qstandardpaths::writablelocation(qstandardpaths::homelocation) + "/justtake.jpg";
    qfile file(strimagepath);
    if(file.exists())
    {
        this->setstylesheet(qstring("#firstwidget{border-image:url(%1)}").arg(strimagepath));
    }else
    {
        this->setstylesheet("background-color:white");
    }

 

大家可以根据自己的业务需求进行扩展,评论区随时交流。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网