[Solved] QTextStream: Move to a particulary line in a .dat file
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.
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
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.
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.