Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1415618
  • 博文数量: 241
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 2253
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-11 22:27
个人简介

--

文章分类

全部博文(241)

文章存档

2021年(3)

2019年(6)

2018年(1)

2017年(9)

2016年(21)

2015年(50)

2014年(125)

2013年(26)

我的朋友

分类: C/C++

2016-08-20 22:47:06

1、需求
打开某个文件

2、逻辑

点击(此处)折叠或打开

  1. void Dialog::getOpenFile()
  2. {
  3.     QString path = QFileDialog::getOpenFileName(this, tr("Open Image"), ".", tr("Image Files(*.jpg *.png)"));
  4.     if(path.length() == 0) {
  5.             QMessageBox::information(NULL, tr("Path"), tr("You didn't select any files."));
  6.     } else {
  7.             std::string str = path.toStdString();
  8.             const char* ch = str.c_str();
  9.             QFileInfo fi;
  10.             fi = QFileInfo(path);
  11.             QString filePath;
  12.             QString fileName;
  13.             filePath = fi.absolutePath();
  14.             fileName = fi.fileName();
  15.             QMessageBox::information(NULL, tr("Path"), tr("You selected ") + path + ",path=" + filePath + ",name=" + fileName );
  16.     }
  17.     accept();
  18. }

点击(此处)折叠或打开

  1. void Dialog::getOpenFile()
  2. {
  3.     QString path = QFileDialog::getOpenFileName(this, tr("Open Image"), ".", tr("Image Files(*.jpg *.png)"));
  4.     if(path.length() == 0) {
  5.             QMessageBox::information(NULL, tr("Path"), tr("You didn't select any files."));
  6.     } else {
  7.             std::string str = path.toStdString();
  8.             const char* ch = str.c_str();
  9.             QFileInfo fi;
  10.             fi = QFileInfo(path);
  11.             //获取绝对路径和名称
  12.             QString filePath;
  13.             QString fileName;
  14.             filePath = fi.absolutePath();
  15.             fileName = fi.fileName();
  16.             //更改名称,不能是中文
  17.             QString newName = filePath+"/111.PNG";
  18.             std::string str2 = newName.toStdString();
  19.             const char* ch2 = str2.c_str();
  20.             int ret = rename(ch,ch2);
  21.             QMessageBox::information(NULL, tr("Path"), tr("You selected ") + path + ",path=" + filePath + ",name=" + fileName );
  22.     }
  23.     accept();
  24. }

3、注意中文支持:


参考QString和char*的转换
http://www.cnblogs.com/Romi/archive/2012/03/12/2392478.html


4、附加需求
解压文件:
Rar.exe e  log.rar
C:\Program Files\WinRAR\Rar.exe

阅读(746) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~