Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2631538
  • 博文数量: 416
  • 博客积分: 10220
  • 博客等级: 上将
  • 技术积分: 4193
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-15 09:47
文章分类

全部博文(416)

文章存档

2022年(1)

2021年(1)

2020年(1)

2019年(5)

2018年(7)

2017年(6)

2016年(7)

2015年(11)

2014年(1)

2012年(5)

2011年(7)

2010年(35)

2009年(64)

2008年(48)

2007年(177)

2006年(40)

我的朋友

分类: C/C++

2009-09-15 17:01:17

   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;
}
阅读(2983) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~