Qt:如何创建一个文件(其路径需要目录)
Qt: how to create a file (with directorys required by its path)?
Qt:如何创建一个包含路径所需目录的文件?如果它不存在,则说创建"./gg/ggg./fff/ff/file.dd"?
您可以将路径设置为
QDir directory("gg/ggg./fff/ff/file");
然后,您可以创建一个文件夹,例如
QDir().mkdir("MyFolder");
bool QDir::mkdir ( const QString & dirName ) const
Creates a sub-directory called dirName.
Returns true on success; otherwise returns false.
See also rmdir().
请参阅 http://doc.qt.io/qt-5/qdir.html#mkdir
bool QDir::mkpath ( const QString & dirPath ) const
Creates the directory path dirPath.
The function will create all parent directories necessary to create the directory.
Returns true if successful; otherwise returns false.
请参阅 http://doc.qt.io/qt-5/qdir.html#mkpath
bool QFile::open ( OpenMode mode ) [virtual]
Reimplemented from QIODevice::open().
Opens the file using OpenMode mode, returning true if successful; otherwise false.
In WriteOnly or ReadWrite mode, if the relevant file does not already exist, this function will try to create a new file before opening it.
请参阅 http://doc.qt.io/qt-5/qfile.html#open
相关文章:
- 从函数角度看ID到文件路径的内部与外部映射
- 在C++中设置基于操作系统的文件路径
- Windows 非 ASCII 文件路径
- 非 ASCII 文件路径窗口
- C++和带有国家符号的文件路径(也许用 UTF8 编码)
- 如何为文件路径使用变量?
- 包括 VS Code 上的完整文件路径
- 如何使用提升获取当前文件路径?
- 如何在 c++ 中获取当前文件路径?
- 保存json文件后如何返回文件路径
- 从 C++ 中的文件路径中提取文件名
- 是否可以将文件路径传递给Qt中的setStyleSheet()
- 无法转换 .CATPart 文件.错误:输入文件路径似乎包含不支持的字符
- 在结构函数之间传递文件路径 C++ 编辑:修复LNK2019错误
- 提供依赖于输入的程序的文件路径
- 从 QFileSystemModel 中的文件路径和文件名获取 QModelIndex
- 如何更改变量文件名的文件路径?
- cmake:包括vs vs add_subDirectory:相对标头文件路径
- 在OSX中使用CGDisplayStream存储屏幕记录的特定文件路径
- 如何在另一个系统上启用文件路径