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] QTextStream: Move to a particulary line in a .dat file
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.3k 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
    silep
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • S Offline
        S Offline
        silep
        wrote on last edited by
        #3

        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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0

          • Login

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