Results 1 to 12 of 12

Thread: replace line of a file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: replace line of a file

    Nothing to do with Qt per se. General steps:
    • Open original file for reading
    • Open temporary file for writing
    • Write lines from original file until you reach the line you want to replace
    • Write the replacement line
    • Skip the line from the original file
    • Write lines from original file until end of file
    • Close temporary and original file
    • If all of above successful, remove original file and copy/rename temporary file.


    Start with QFile, QTextStream and QTemporaryFile in the Qt docs. The temporary file could be in-memory; see QBuffer.

  2. The following user says thank you to ChrisW67 for this useful post:

    frankiefrank (28th August 2013)

Similar Threads

  1. New line when writing a File
    By locke in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2011, 11:27
  2. How to write something on a text file on a certain line?
    By Bong.Da.City in forum Qt Programming
    Replies: 1
    Last Post: 17th December 2010, 21:01
  3. Replies: 3
    Last Post: 3rd May 2009, 08:58
  4. How to write something in line of txt file
    By Zergi in forum Qt Programming
    Replies: 2
    Last Post: 24th December 2007, 10:02
  5. How to read line from file
    By Krishnacins in forum Newbie
    Replies: 10
    Last Post: 1st June 2006, 23:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.