gpt4 book ai didi

c++ - Qt:如何创建文件(其路径需要目录)?

转载 作者:行者123 更新时间:2023-11-28 00:57:14 26 4
gpt4 key购买 nike

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

关于c++ - Qt:如何创建文件(其路径需要目录)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10448758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com