欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

QT获取linux下的当年用户名

程序员文章站 2023-02-05 18:11:14
故事背景:客户端启动的时候需要加载机器/home/xx/test.jpg的图片作为背景图,但是有的机器用户名叫AAA,有的机器名叫BBB,所以我需要获取当前用户的home目录 技术调研:QStandardPaths QString strImagePath = QStandardPaths::wri ......

故事背景:客户端启动的时候需要加载机器/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");
    }

 

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