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 217 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 25 Mar 2024, 09:26 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??

    J 1 Reply Last reply 25 Mar 2024, 09:43
    0
    • S SeyMohsenFls
      25 Mar 2024, 09:26

      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??

      J Offline
      J Offline
      JonB
      wrote on 25 Mar 2024, 09:43 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 25 Mar 2024, 10:09
      0
      • J JonB
        25 Mar 2024, 09:43

        @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 25 Mar 2024, 10:09 last edited by
        #3

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

        J J 2 Replies Last reply 25 Mar 2024, 10:47
        0
        • S SeyMohsenFls
          25 Mar 2024, 10:09

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

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 25 Mar 2024, 10:47 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
            25 Mar 2024, 10:09

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

            J Offline
            J Offline
            JonB
            wrote on 25 Mar 2024, 11:09 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

            5/5

            25 Mar 2024, 11:09

            • Login

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