Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] QTextStream: Move to a particulary line in a .dat file

    General and Desktop
    2
    4
    2040
    Loading More Posts
    • 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
      silep last edited by

      Hello,

      I have a file .dat to read, and I would like to move my cursor directly at a particularly line. How could I do that with QTextStream?

      The lines are like that in the .dat. There is text before and I try to arrive at the word "coordinate.."
      @coordinate center focal center
      (1,1) (20,0) (0,0)
      (1,2) (520,0) (0,0)
      (1,3) (0,0) (0,0)@

      I also search something like QTextStream::readLine().section(separator, -1).toFloat(), but to read only until the first number (and then the second, etc), and not the whole line. Would you have a clue to give me?

      Thank you in advance.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        You would need to use seek but have to know/calculate the position. However if you have a line number you can go for the quick and dirty for loop that reads the number of line needed.

        For the second point, you can use readine + split so you can get a list of line entry that you can use as you wish.

        Hope it helps

        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 Reply Quote 0
        • S
          silep last edited by

          Thank you for your reply!

          For the first point, the problem is that the line number before can change, so I cannot program it with number of line or a fixed position.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            When you want to read a specific line, just move the stream back to the beginning and go the line position.

            However, depending on the file size, you could also simply load it's content in memory like in a QVector<YourClassContainingTheData> and use that rather than play with the file.

            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 Reply Quote 0
            • First post
              Last post