Problem creating text file
-
I am having a problem creating a text file, I populated a QStringList with the rows I want to print, I have verified that each row ends only with \r\n using Qt Creator.
Here is the code that writes the list to the file:
QFile fCSV(strFilename); if ( fCSV.open(QIODevice::ReadWrite | QIODevice::Text) == true ) { QTextStream tsCSV(&fCSV); foreach( strRow, slstRows ) { tsCSV << strRow; } fCSV.close(); }
What I'm seeing when I open this file in an editor that shows end of line terminators is that each line ends with \r\r\n, where is this coming from?
I've looked at the code and I only ever append \r\n once to each string and as I said using Qt Creator the bytes ending on the QString end only in 13 (\r) followed by 10 (\n).
Yet when it's written to file this is changed to \r\r\n.
-
@SPlatten
Qt does it. it appends the native platforms convention for line ending.
Since you are on windows i assume, you get the "\n" replaced with "\r\n"Dont use QTextStream, but write the binary data directly:
QFile fCSV(strFilename); if ( fCSV.open(QIODevice::WriteOnly) ) { for( const QString & strRow : qAsConst(slstRows) ) fCSV.write( strRow.toUtf8() ); fCSV.close(); }
-
@raven-worx Thank you!