Have you tried combining both answers?
so: stream << ui->textEdit->plainText(); // and obviously with the function Write2 member in the same class that has the ui member.