//获取保存路径 QString savepath = QFileDialog::getSaveFileName(this); //创建文件对象 QFile file(savepath); if(!file.open(QIODevice::ReadWrite)) //读写方式打开 { ui->statusBar->showMessage("打开文件失败"); return; } QString msg = ui->textEdit->toPlainText(); //写文件 file.write(msg.toUtf8()); file.close();