gpt4 book ai didi

qt - QFile::ReadAll() 返回一个空数组

转载 作者:行者123 更新时间:2023-12-01 13:22:25 24 4
gpt4 key购买 nike

造成这种情况的一些常见原因是什么?我的第一个想法是我正在读取的文件是只读的,但我已经检查过了。

调用它的代码是:

QFile histogramFile(fileName);
quint64 fileSize = histogramFile.size();
QByteArray histogramByteArray = histogramFile.readAll();

最佳答案

引自documentation :

This function has no way of reporting errors; returning an empty QByteArray can mean either that no data was currently available for reading, or that an error occurred.

您可以使用 histogramFile.errorString() 查询最后一个错误:

Returns a human-readable description of the last device error that occurred.

在您的情况下,您忘记了 open文件,例如:

QFile histogramFile(fileName);
if (histogramFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
QByteArray histogramByteArray = histogramFile.readAll();
}

关于qt - QFile::ReadAll() 返回一个空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31986404/

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