qt 文件的写入与读出

QString ss = ui -> textEdit -> toPlainText ();
        ui->textBrowser->append(ss);
        ui->textEdit->clear();
        QFile file(str1);
        if(!file.open(QIODevice::WriteOnly))
        {
            QMessageBox::warning(this,tr("Warning"),tr("file wrong"),QMessageBox::Yes);
        }
        QTextStream out(&file);
        out<<ss;
        file.close();
}

 QFile file("qt2");
        if(!file.open(QIODevice::ReadOnly))
        {
            QMessageBox::warning(this,tr("Warning"),tr("file wrong"),QMessageBox::Yes);
        }
        QTextStream in(&file);
        while(!in.atEnd())
        {
         QString line=in.readAll();
         ui->textBrowser->append("qt2");
         ui->textBrowser->append(line);
        }
        file.close();

你可能感兴趣的:(qt,greator)