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. Update data in a CSV file
Forum Updated to NodeBB v4.3 + New Features

Update data in a CSV file

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 223 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.
  • S Offline
    S Offline
    SeyMohsenFls
    wrote on last edited by
    #1

    Hello guys. I'm trying to open a csv file and change some data in the file.
    But I can just append in bottom the file by this option (QIODevice::Append).
    What's the solution to update any data from anywhere in csv file??

    JonBJ 1 Reply Last reply
    0
    • S SeyMohsenFls

      Hello guys. I'm trying to open a csv file and change some data in the file.
      But I can just append in bottom the file by this option (QIODevice::Append).
      What's the solution to update any data from anywhere in csv file??

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @SeyMohsenFls
      Since it is a text file you cannot (or at least should not, because you probably don't understand the consequences) update (change) anything inside it. Like any text file, you need to rewrite the whole file if you want to alter something.

      S 1 Reply Last reply
      0
      • JonBJ JonB

        @SeyMohsenFls
        Since it is a text file you cannot (or at least should not, because you probably don't understand the consequences) update (change) anything inside it. Like any text file, you need to rewrite the whole file if you want to alter something.

        S Offline
        S Offline
        SeyMohsenFls
        wrote on last edited by
        #3

        @JonB
        So, What is the best and easiest way to save and change big data?

        jsulmJ JonBJ 2 Replies Last reply
        0
        • S SeyMohsenFls

          @JonB
          So, What is the best and easiest way to save and change big data?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @SeyMohsenFls Read the file, modify the data, write it back to file

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • S SeyMohsenFls

            @JonB
            So, What is the best and easiest way to save and change big data?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @SeyMohsenFls
            As stated, you have to rewrite the complete file, can't be clearer. You have two possible ways:

            • Read whole file into memory, in some structure (even if it's just a list of lines). Make modifications to it in memory. Write whole file back when completed, e.g. overwriting original file. This is how e.g. a text editor or sort works.
            • Open existing file for read, open a new file for write. As you read each line in, make any modifications and write new line out. At the end probably/perhaps delete original file and rename new file to that. This is how e.g. sed works.

            Either way you completely rewrite new file. Difference is how much memory you use.

            1 Reply Last reply
            3

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved