Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Unexpected behavior with atEnd()
Forum Updated to NodeBB v4.3 + New Features

[Solved] Unexpected behavior with atEnd()

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Endless
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      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.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Endless
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved