QTextStream readLine new line

QTexStream::readLine() function is a convenient function that can read a line from a file at a time. However, you must pay attention to so called new line. You may find what readLine reads are multiple lines as seen in your text editor like notepad or wordpad. So a line as seen by readLine is not a line in the eyes of your text editor. In fact, the readLine function reads all characters before a LF(Line Feed, ascii decimal code 10, hex code 0x0a) character and calls those characters a line. Those characters may include CRs(Carriage Return, ascii decimal code 13, hex code 0x0d). Many text editors show what follow CR on a new line as well(All text editors show what follow LF in a new line). This is the reason why a line read by QTexStream::readLine() looks as if it has more than one line in your editor.

Although a line read by QTexStream::readLine()  can include CRs in middle of it, it never includes the trailing end-of-line characters such as “\n” or “\r\n” so you do not need to call QString::trimmed to get rid of them.



If you like my content, please consider buying me a coffee. Buy me a coffeeBuy me a coffee Thank you for your support!
Posted in

Leave a Reply