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. Clearing existing file
Forum Updated to NodeBB v4.3 + New Features

Clearing existing file

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 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.
  • JeroentjehomeJ Offline
    JeroentjehomeJ Offline
    Jeroentjehome
    wrote on last edited by
    #1

    Hi guys,
    Maybe just a trivial question, but I have to write some data to a file (and off course open it again later on). The problem I encounter is that when the file already exists the "old" data in the file will stay there when the new data (that overwrites this) is shorter then the old data. In QFile the only thing I could find is QFile.resize(0); I'm using a QTextStream to fill the data in the file.

    Are there any better ways of doing this? It does work, but IYAM it's not real pretty, or is it?

    Greetz

    Greetz, Jeroen

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

      I'm not sure if I understand your issue so I prefer to post a snippet.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        Try to open the file with QIODevide::Truncate flag like

        @QFile file(path);
        file.open(QIODevice::WriteOnly | QIODevice::Truncate);@

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BelenMuñoz
          wrote on last edited by
          #4

          [quote author="Sam" date="1359467461"]Try to open the file with QIODevide::Truncate flag.[/quote]

          If the problem persists after that, try to remove the file before writing the new data.

          Me casé con un enano pa jartarme de reí.

          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