故事背景:客户端启动的时候需要加载机器/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"); }
大家可以根据自己的业务需求进行扩展,评论区随时交流。
如对本文有疑问, 点击进行留言回复!!
linux下文本编辑器vim的使用方法(复制、粘贴、替换、行号、撤销、多文件操作)
网友评论