QDesktopServices::storageLocation(QDesktopServices::TempLocation);返回临时目录,有的机器可能返回到:C:\WINDOWS\TEMP,而不是用户临时目录下 Documents and Settings\[系统当前用户]\Local Settings\Temp\
下面函数纠正此问题,在win7,vista下未测试过
QString Form::getUserTempDir()
{
QString tmpDir = QDesktopServices::storageLocation(QDesktopServices::TempLocation);
QString userHome = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
QString currentUser = userHome.mid(userHome.lastIndexOf("/") + 1);
if (!tmpDir.isEmpty() && tmpDir.indexOf(currentUser)==-1)
{
#ifdef Q_WS_WIN
int version = QSysInfo::windowsVersion();
if (version == QSysInfo::WV_VISTA || version == QSysInfo::WV_WINDOWS7)
{
QString appData = QDesktopServices::storageLocation(QDesktopServices::ApplicationsLocation);
tmpDir = QString("%1/Local/Temp").arg(userHome);
}
else
{
tmpDir = QString("%1/Local Settings/Temp").arg(userHome);
}
qDebug() << "Not right";
#endif
}
return tmpDir;
}
阅读(3075) | 评论(0) | 转发(0) |