我有以下创建文件并写入文件的代码。
QFile file(saveFilename);
file.open(QIODevice::WriteOnly);
QTextStream out(&file);
out << name + " - " + size + "\n";
file.close();
这个文件将保存在哪里?
我有一个名为 QString saveFileDirectory
的变量,我希望将文件保存在其中。
关于如何实现这一目标的任何提示? 谢谢。
最佳答案
如果您只提供文件名,文件将保存在当前工作目录中。为了将其保存到特定目录中,您必须提供 QFile
对象的完整文件路径。例如:
QString fileName;
QString directoryName;
QString filePath = directoryName + '/' + fileName;
QFile file(filePath);
if (file.open(QIODevice::WriteOnly)) {
// Write the file content.
}
关于c++ - 设置QFIle保存目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24936564/