废话不说直接上代码
1.
QString displayString;
QFile file("/home/alvin/text.txt");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug()<<"Can't open the file!"<<endl;
}
while(!file.atEnd())
{
QByteArray line = file.readLine();
QString str(line);
qDebug()<< str;
displayString.append(str);
}
ui->textEdit->clear();
ui->textEdit->setPlainText(displayString);
2.
QString displayString;
QFile file("/home/alvin/text.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&f