Important: Please read the Qt Code of Conduct -

How can i save the content of QTextEdit to a file?

  • I got some problem with this.

    I tried this:
    QFile outfile;
    QTextStream out(&outfile);
    out << ui->QTextEdit->toPlainText() << endl;
    But some information lost.

    If I write:"
    "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


    to: | QIODevice::Text);@

  • Thanks!
    It helps me a lot!

  • You are welcome..!!! Please set the topic as [SOLVED].

Log in to reply