void MainWindow::on_pushButton_clicked(){ QFile file("n1.cpp"); file.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream in(&file); while (!in.atEnd()) { QString line; in>>line; ui->textEdit->append(line); } file.close();}
void MainWindow::on_pushButton_clicked(){ QFile file("n1.cpp"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) setWindowTitle("No file!"); else setWindowTitle("Yes file!"); QTextStream in(&file); while (!in.atEnd()) { QString line; in>>line; ui->textEdit->append(line); } file.close();}
#include <QApplication>#include <QDebug>#include <QFile>int main(int argc, char **argv){ QFile f("test.txt"); if (!f.exists()) { qDebug("File isn't exist..."); } else { if (!f.open(QIODevice::ReadOnly)) { qDebug("File isn't open..."); } else { while(!f.atEnd()) qDebug(f.readLine()); } } return 1;}