Erlo

QT获取linux下的当年用户名

2019-12-05 15:30:04 发布   318 浏览  
页面报错/反馈
收藏 点赞

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

 

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

登录查看全部

参与评论

评论留言

还没有评论留言,赶紧来抢楼吧~~

手机查看

返回顶部

给这篇文章打个标签吧~

棒极了 糟糕透顶 好文章 PHP JAVA JS 小程序 Python SEO MySql 确认