Results 1 to 4 of 4

Thread: Reading data from cvs file into String & deleting part of String data n write 2 file

  1. #1
    Join Date
    Jun 2011
    Posts
    26
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Question Reading data from cvs file into String & deleting part of String data n write 2 file

    Hi,
    I AM NEW TO Qt.My question is how do i read data from cvs file which contains information of many users created by ADMIN in one column.Now if i want to delete one user then i have to remove his details from the file.So please help in achieving this.
    Presently i am able to read data from file into QString but i am not getting how to manipulate the data inside the String after comparing it with user name and id(these are used to find & delete the user from file).Please share the code if any which may be helpful for me...

    Thanks in advance..

  2. #2
    Join Date
    Aug 2008
    Posts
    45
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading data from cvs file into String & deleting part of String data n write 2

    Umm, I think you should read the data from the file into a string list (QStringList) where each item is a user.
    Then you modify the list, like removing of adding of new items/users.
    And finally, you write the list back to the file.

    Hardest part is the reading of the file into that list. Rest should be a breeze to implement.

  3. #3
    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: Reading data from cvs file into String & deleting part of String data n write 2

    A naïve approach would be:
    1. Open input file and output file: QFile::open()
    2. Read a line from the input file: QFile::readLine() or QTextStream::readLine()
    3. Split the line on the comma character: QString::split()
    4. Check the fields and if the line is to be kept write it to the output file: QFile::write() or QTextStream operator <<
    5. Repeat from 2 until input file exhausted
    6. Close files
    7. On successful completion replace input file with output file


    However, "CSV File" covers a multitude of slightly different formats: quotes, no quotes, embedded commas, embedded new lines etc. More complex handling is required for many of these scenarios.

  4. #4
    Join Date
    Jun 2011
    Posts
    26
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Reading data from cvs file into String & deleting part of String data n write 2

    Thank you so much... It helped me a lot..
    Finally I achieved it..

    Thank you Chris once again.. I was able to do it..
    Meet u again with some problems...

Similar Threads

  1. Reading XML file into a data file correctly?
    By falconium in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2011, 18:55
  2. Reading string in Utf8 from binary file
    By iddqd in forum Newbie
    Replies: 3
    Last Post: 19th July 2010, 06:16
  3. Reading data from xls file
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2010, 09:33
  4. reading data from file
    By offline in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2010, 10:31
  5. How to write data into a file
    By grsandeep85 in forum Qt Programming
    Replies: 9
    Last Post: 21st July 2009, 08:51

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.