Are you adding QIODevice::Text to the OpenMode? If you want newlines in the output, you have to explicitly write them if you are using QIODevice directly to write the files:
iodevice.write( mystring );
iodevice.write( "\n" );
iodevice.write( mystring );
iodevice.write( "\n" );
To copy to clipboard, switch view to plain text mode
But for text files, it is more usual to create a QTextStream and a QFile and use that combination to write and read text data:
// Writing:
return;
out << mystring << "\n";
// Reading:
return;
while (!in.atEnd()) {
QString myString
= in.
readLine();
// readline automatically removes the EOL // do something with "mystring"
}
// Writing:
QFile file("out.txt");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream out(&file);
out << mystring << "\n";
// Reading:
QFile file("in.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file);
while (!in.atEnd()) {
QString myString = in.readLine(); // readline automatically removes the EOL
// do something with "mystring"
}
To copy to clipboard, switch view to plain text mode
Bookmarks