How can i save the content of QTextEdit to a file?
-
I got some problem with this.
I tried this:
@
QFile outfile;
outfile.setFileName("detail.txt");
outfile.open(QIODevice::Append);
QTextStream out(&outfile);
out << ui->QTextEdit->toPlainText() << endl;
@
But some information lost.If I write:"
1
2
3
"in the QTextEdit , I will get "123" in the file. All the "\n" are ignored.Anybody knows how can keep the "\n" in my file?
[edit] code wrappings added, koahnig
-
I know why……
In fact, there are 3 "\n". But in windows, "\n" is replaced by "\r\n". When I copy the "123" to MSword, I finally find out that....
-
Hi,
Just change the following lines in your code
from:
@outfile.open(QIODevice::Append);@
to:
@outfile.open(QIODevice::Append | QIODevice::Text);@
-
Thanks!
It helps me a lot! -
You are welcome..!!! Please set the topic as [SOLVED].