gpt4 book ai didi

c++ - QFile:找不到目录

转载 作者:行者123 更新时间:2023-11-28 05:49:32 27 4
gpt4 key购买 nike

我需要编写一个控制台应用程序来接收一个文件,打开它,然后根据文本文件中的信息调用另一个过程。唯一的问题是 QFile::errorString() 返回:

No such file or directory.

我一直在我必须的所有程序中使用此实现,是的,该文件存在于该目录中。

代码是:

QFile fileName("D:/file.txt");
QString read_from_file;
if(fileName.open(QIODevice::ReadOnly)){
QTextStream in(&fileName);
while(!in.atEnd())
{
read_from_file = in.readLine();
qDebug()<<read_from_file;
}
fileName.close();
}
qDebug()<<fileName.errorString();

最佳答案

确保该文件确实存在。


正如您在评论中指出的那样,问题出在 hidden file extensions在 Windows 上。

  1. Open Folder Options by clicking the Start button, clicking Control Panel, clicking Appearance and Personalization, and then clicking Folder Options.

  2. Click the View tab, and then Advanced settings <...>

    • To show file name extensions, clear the Hide extensions for known file types check box, and then click OK.

关于c++ - QFile:找不到目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35548010/

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