1、需求
打开某个文件
2、逻辑
-
void Dialog::getOpenFile()
-
{
-
QString path = QFileDialog::getOpenFileName(this, tr("Open Image"), ".", tr("Image Files(*.jpg *.png)"));
-
if(path.length() == 0) {
-
QMessageBox::information(NULL, tr("Path"), tr("You didn't select any files."));
-
} else {
-
std::string str = path.toStdString();
-
const char* ch = str.c_str();
-
QFileInfo fi;
-
fi = QFileInfo(path);
-
QString filePath;
-
QString fileName;
-
filePath = fi.absolutePath();
-
fileName = fi.fileName();
-
QMessageBox::information(NULL, tr("Path"), tr("You selected ") + path + ",path=" + filePath + ",name=" + fileName );
-
}
-
accept();
-
}
-
void Dialog::getOpenFile()
-
{
-
QString path = QFileDialog::getOpenFileName(this, tr("Open Image"), ".", tr("Image Files(*.jpg *.png)"));
-
if(path.length() == 0) {
-
QMessageBox::information(NULL, tr("Path"), tr("You didn't select any files."));
-
} else {
-
std::string str = path.toStdString();
-
const char* ch = str.c_str();
-
QFileInfo fi;
-
fi = QFileInfo(path);
-
//获取绝对路径和名称
-
QString filePath;
-
QString fileName;
-
filePath = fi.absolutePath();
-
fileName = fi.fileName();
-
//更改名称,不能是中文
-
QString newName = filePath+"/111.PNG";
-
std::string str2 = newName.toStdString();
-
const char* ch2 = str2.c_str();
-
int ret = rename(ch,ch2);
-
QMessageBox::information(NULL, tr("Path"), tr("You selected ") + path + ",path=" + filePath + ",name=" + fileName );
-
}
-
accept();
-
}
参考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
阅读(781) | 评论(0) | 转发(0) |