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. [SOLVED] How can I override a text line in txt file.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How can I override a text line in txt file.

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 5.0k 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.
  • N Offline
    N Offline
    Neutrox
    wrote on last edited by
    #3

    In my txt file has just 3 paths that I can override.

    1 Reply Last reply
    0
    • IamSumitI Offline
      IamSumitI Offline
      IamSumit
      wrote on last edited by
      #4

      Hii

      your given code is working right if i remove line 11.
      i have doubt on line 11
      What is this _directory3 ?
      is this same as item1 or item2 ?
      if yes How are you getting _directory3 ?

      Be Cute

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #5

        Then you should just read the file line by line in e.g. a QStringList. Replace the line you modified in the QStringList and then overwrite the content of the original file with the content of the QStringList.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Neutrox
          wrote on last edited by
          #6

          Can you show me an example with this?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #7

            Of reading a file line by line ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • N Offline
              N Offline
              Neutrox
              wrote on last edited by
              #8

              No. I don't now how to use QStringList in this case.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #9

                Then please, take some time to read the documentation of this class.
                One way:
                @QStringList lines
                //open file etc.
                while(!steam.atEnd()) {
                lines << stram.readLine();
                } @

                There are also other way to do that e.g. using QString::split

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  Neutrox
                  wrote on last edited by
                  #10

                  The solution was simpler than I imagined.
                  Simply put:
                  @if(!file3.open(QFile::ReadWrite | QFile::Truncate)){
                  qDebug() << "could not open file for writing";
                  return;@

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    With that you don't just change one line like you ask for, you are overwriting everything.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      Neutrox
                      wrote on last edited by
                      #12

                      Yes, but I also rewrite those who have not been changed.

                      1 Reply Last reply
                      0
                      • IamSumitI Offline
                        IamSumitI Offline
                        IamSumit
                        wrote on last edited by
                        #13

                        if your problem is solved then make this title as SOLVED by adding [SOLVED] tag before the title.

                        Be Cute

                        1 Reply Last reply
                        0

                        • Login

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