QFile file(filepath);
if (file.open(QFile::WriteOnly | QIODevice::Text))
{
    QTextStream ts(&file);
    ts.setGenerateByteOrderMark(true);  //设置UTF-8需要加BOM
    ts.setCodec("UTF-8");
    ts << textEdit.document()->toPlainText();
    file.close();
}