qt文件保存

void MainWindow::on_pushButtonSave_clicked()
{
    QString fileName = QFileDialog::getSaveFileName(this,
                                                    tr("保存当前日志"),
                                                    "",
                                                    tr("日志文件(*.txt)"));
    QFile file(fileName);

    if (!file.open(QIODevice::WriteOnly|QIODevice::Text))
    {
        QMessageBox::critical(this, "critical", tr("文件保存失败!"),
                              QMessageBox::Yes, QMessageBox::Yes);
    }
    else
    {
        QTextStream stream(&file);
        stream << ui->textBrowser->toPlainText();
        stream.flush();
        file.close();
    }
}

你可能感兴趣的:(qt)