Linux环境下bool QFile::rename
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Linux环境下bool QFile::rename,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1261字,纯文字阅读大概需要2分钟。
内容图文
![Linux环境下bool QFile::rename](/upload/InfoBanner/zyjiaocheng/929/044dc2b0433649f5b792b00f43f5875d.jpg)
bool QFile::rename(const QString &newName)
1、Renames the file currently specified by fileName() to newName. Returns true
if successful; otherwise returns false
.
重命名当前指定的文件名。如果成功返回 true ,其他返回 false。
2、If a file with the name newName already exists, rename() returns false
(i.e., QFile will not overwrite it).
如果新命名的文件已经存在,函数将返回 false。(QFile 不会覆盖它)
3、The file is closed before it is renamed.
当需要重命名文件的时候,这个文件必须为关闭状态。
4、If the rename operation fails, Qt will attempt to copy this file's contents to newName, and then remove this file, keeping only newName. If that copy operation fails or this file can't be removed, the destination file newName is removed to restore the old state.
如果重命名操作失败,Qt 将会尝试拷贝改文件的内容至新文件,然后删除旧文件。如果拷贝操作失败或旧文件不能够被删除,将删除新文件以保持旧文件的状态。
例:
QString strAbsPath = "/home/test.txt";
QFile file("strAbsPath ");
file.rename("/home/test1.txt");
注意:
1、传入参数必须为目标路径+文件名,修改路径也应该是目标路径+文件名。若直接传入文件名,QFile将会根据环境变量寻找改文件,rename时也会将其储存至环境变量定义的路径。
2、bool QFile::rename(const QString &oldName, const QString &newName) (静态重载函数)
内容总结
以上是互联网集市为您收集整理的Linux环境下bool QFile::rename全部内容,希望文章能够帮你解决Linux环境下bool QFile::rename所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。