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