Qt中如何获取电脑桌面路径,及图片的重写
2017-03-19 本文已影响325人
明白已晚
第一步建立一个MainWindow
第二步拖入一个QpushButton
第三步转到槽(或者自己写信号)、
第四步写函数实体
void MainWindow::on_pushButton_clicked()
{
const auto paths=QFileDialog:: getOpenFileNames(this,"please choose PNG",QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),"*.png");//打开文件目录,从桌面找,且是文件应写入的目录(这里主要目的是图片重写)
if(paths.isEmpty())
{
return;
}
for(const auto &path:paths)//c++11标准,遍历paths里面的内容
{
QImage image(path);
if(image.isNull())
{continue;}
if(!image.save(path,"PNG"))
{
QMessageBox::warning(this,"Error",QString("%1 save fail").arg(path));
}
}
QMessageBox::information(this,"Done","All png image processing is completed");
}



源码下载