Qt没有直接的接口去获取到当前系统用户名,只能够间接的通过现有的接口去获取。(比如下边的例子通过获取home路径)
c++ //Qt4 version
QString getUserName()
{
QString userName = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
userName = userName.section("/", -1, -1);
return userName;
}
//Qt5 version
QString getUserName()
{
QString userPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
QString userName = userPath.section("/", -1, -1);
return userName;
}
已有0条评论
还没有任何评论,你来说两句吧!