Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can i save the content of QTextEdit to a file?
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 14.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    silver1991
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      silver1991
      wrote on last edited by
      #2

      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....

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        Hi,

        Just change the following lines in your code

        from:

        @outfile.open(QIODevice::Append);@

        to:

        @outfile.open(QIODevice::Append | QIODevice::Text);@

        1 Reply Last reply
        0
        • S Offline
          S Offline
          silver1991
          wrote on last edited by
          #4

          Thanks!
          It helps me a lot!

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved