QDir使用时的一点注意事项
当调用QDir的相关方法
( 例如:rename(),removeRecursively())时需要注意:
当操作文件时不应当在传入参数后加上”/“
当操作文件夹时要在传入参数后面加入”/“
bool ProjectmanagementPlugin::renameFolder(const QString &folderPath, const QString &newFolderName) { QString oldPath=jsonFileInfo.absolutePath()+"/"+solution->getSolutionName()+"/"+folderPath+"/"; QDir dir(jsonFileInfo.absolutePath()+"/"+solution->getSolutionName()+"/"+folderPath); if (!dir.exists()) { QMessageBox::critical(nullptr,tr("Error"),tr("Folder does not exist.")); return false; } //获取上层文件夹 dir.cdUp(); QString newFolderPath = dir.absolutePath() + "/" + newFolderName+"/"; if (dir.rename(oldPath, newFolderPath)) { emit sendSuccessEvent(1,tr("Folder renamed successfully.")); return true; } else { return false; } }
相关变量值:


浙公网安备 33010602011771号