Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. [not really] QFile open for append adding extra newline 8-(
Forum Updated to NodeBB v4.3 + New Features

[not really] QFile open for append adding extra newline 8-(

Scheduled Pinned Locked Moved Brainstorm
2 Posts 1 Posters 7.1k 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.
  • J Offline
    J Offline
    johnea
    wrote on last edited by
    #1

    This seems like it should be so easy 8-(

    I have a text file, something like this:
    @
    line1
    line2
    line3
    @

    There is no empty line at the end.

    I open the file in append mode and create a QTextStream.

    @
    QFile file(filename);
    file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
    QTextStream out(&file);
    @

    If I write without inserting '\n' (or endl) the text goes right on the of the last line:

    @
    out << "line4";
    @

    The file now looks like this:
    @
    line1
    line2
    line3line4
    @

    However if I insert '\n' (or endl) there is always an empty line between the previous EOF and the line I append:

    @
    out << endl << "line4";
    @

    The file now looks like this:
    @
    line1
    line2
    line3

    line4
    @

    Is there some way to append without creating this extra empty line?

    Thanks for any tips!!!

    johnea

    1 Reply Last reply
    0
    • J Offline
      J Offline
      johnea
      wrote on last edited by
      #2

      This was VIM's fault 8-(

      It adds an EOL at the end that it doesn't show.

      You can prevent this by using ":set binary"

      Sorry, Operator error...

      johnea

      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