QT获取linux下的当前用户名


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

 

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM