gpt4 book ai didi

c++ - QT Creator - 通过 CSV 文件解析

转载 作者:太空宇宙 更新时间:2023-11-04 13:05:34 25 4
gpt4 key购买 nike

好的,所以我正在使用 C++ 的 QT Creator,并且我正在创建一个函数,允许我解析我命名为 getExcelFile 的 CSV 文件。其他一切都工作正常,但由于某种让我发疯的原因,我的代码不会进入我的 while 循环。一些建议会有所帮助!谢谢。

void Widget::getExcelFile(){
//Name of the Qfile object.
//filename is the directory of the file once it has been selected in prompt
QFile thefile(filename);
//If the file isn't successfully open
if (thefile.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug() << "File opened successfully";
//Converts text file to stream
QTextStream in(&thefile);
fileContent=in.readAll();
QString line;
while (!in.atEnd()){
//line = textStream.readLine();//reads line from file
//Will not enter this loop for some odd reason.
qDebug() << "This text does not print out";
}
}

qDebug() << "This prints out successfully";
ui->textEdit->setPlainText(fileContent);
}

最佳答案

您执行了 in.readAll(),之后调用 in.atEnd() 将返回 true。要么删除 in.readlAll() 要么删除 while 循环,为什么你需要两者?

关于c++ - QT Creator - 通过 CSV 文件解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42590875/

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