Results 1 to 3 of 3

Thread: How to write something in line of txt file

  1. #1
    Join Date
    Dec 2007
    Posts
    28
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default How to write something in line of txt file

    Hi

    I have a little problem, exactly i have no idea how to replace sentens in txt file...
    In txt file i have something like thath

    Qt Code:
    1. save option =0
    2. dir exp=0
    To copy to clipboard, switch view to plain text mode 

    Do u know how to change value 0 to 1 in dir exp?

    Best regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to write something in line of txt file

    If you don't change the length, you can seek to the position in the file and simply overwrite the character. But if you want something more complicated, you'll have to read the file into memory (into a string or sth), replace what you want and write everything back.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to write something in line of txt file

    There are several options:
    1. It looks you are dealing with an ini file.
    So you might want to have a look at QSettings, which does all this for you.
    2. if for some reason you can't use QSettigns, but you know exactly what you are looking for in the text (meaning, the text is not arbitrary ) you can just use QString::replace()
    3. If the text to replace is not fixed, then you can use QRegExp in conjunction with QString.
    4. If none of the above helped you, you might want to look QTextEdit facilities, but in contrast to the previous points, its not as little code as the others.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. The following user says thank you to high_flyer for this useful post:

    Zergi (25th December 2007)

Similar Threads

  1. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  2. FSWriteFork in MAC OS to write data to a file.
    By vishal.chauhan in forum General Programming
    Replies: 5
    Last Post: 2nd July 2007, 06:48
  3. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.