[Solved] Unexpected behavior with atEnd()



  • I have a CSV file with the following data:
    one,1.7,3[cr][lf]
    two,3.8,18[cr][lf]

    I then attempt to read the file with the following code:

    @
    QFile file("recipe.csv");
    if(file.open(QFile::ReadOnly | QFile::Text))
    {
    QTextStream in(&file);
    QString myLine = in.readLine();
    if(file.atEnd())
    ui->label_2->setText("EOF");
    @

    The value of myLine is one,1.7,3 (so I know only the first line was read instead of the entire file). The problem is that atEnd() is also true. Shouldn't I get atEnd() true after reading the second line?


  • Moderators

    Just a guess, but the QTextStream may have prefetched and buffered the entire contents of your file, such that file.atEnd() might return true, but in.atEnd() might still return false.



  • Good guess. When I query in.atEnd(), it is false.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.