Results 1 to 8 of 8

Thread: Filing Problem

  1. #1
    Join Date
    May 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Filing Problem

    Hi every one,

    I started using QT recently, i have a text file which contain thousand lines and i want to change the particular lines of the files at particular location. currently i am doing it by buffering the whole file which is just a mess for me. Is there is anyway to change the particular lines of the text file. i am taking the input through the text boxes and want to change those value in the text file.

    Thanks

    Usman

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: Filing Problem

    If the length of the text you want to replace is constant then yes, you can overwrite only the needed characters and it will work. If the text can be of arbitrary length, you have to rewrite the whole file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Filing Problem

    what you mean by the fix length if you mean how many characters you have to change than yes i know how many characters to change can you quote the method of changing the text

    thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: Filing Problem

    Open the file in read/write mode, seek to the position you want to overwrite and write new data. It will replace the old one.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Filing Problem

    hi
    Can you give me some code example please.

  6. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Filing Problem

    if your file reads like this

    Line no 1
    Line 2 is bigger than 1
    Line 3 is small.
    then you have no choice but to write the whole file again.

    but if all of your lines are of same length then you can use
    QTextStream::seek();

  7. #7
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Filing Problem

    What about jumping on a line just by searching \n or a combination of \n\t x-1 times. If desired line number is x.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: Filing Problem

    Quote Originally Posted by usman View Post
    hi
    Can you give me some code example please.
    Come on, man. We're not doing your school projects for you here. We can help but in the end you have to show a bit of initiative yourself. You have been given everything you need - just go and read QFile docs.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 23rd April 2009, 09:05
  2. Replies: 19
    Last Post: 3rd April 2009, 23:17
  3. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  4. Problem with receiving events from QDateEdit
    By gunhelstr in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2006, 11:21
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36

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.