QFile fileRead("D:\1.txt"); if(!fileRead.open(QIODevice::ReadOnly)); { qDebug() << "Error open file READ"; } if(fileRead.isOpen()) { qDebug() << "true isOpen"; } else { qDebug() << "else isOpen"; }
#include <QFile>#include <QFileDialog>#include <QIODevice>#include <QDebug>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); QFile fileRead("D:/1.txt"); if(!fileRead.open(QIODevice::ReadOnly)); { qDebug() << "Error open file READ"; } if(fileRead.isOpen()) { qDebug() << "true"; } else { qDebug() << "else"; }}