I have a program that I basically stole from the Qt website to try to get a file to open. The program refuses to open anything I am confused as to why. I have looked for lots of documentation but found nothing can you please explain why it does not work.
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QTextStream>
#include <QString>
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent)
{
QFile file("C:/n.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file);
QString f=in.readLine();
lab =new QLabel("error",this);
lab->setGeometry(100,100,100,100);
lab->setText(f);
}
QFile::error()
to a variable, then run the code in a debugger and see what that return value is. Then find from the Qt documentation what that error code means. – user362638C:\n.txt
exists? Are you sure it is not, for example,C:\n.txt.txt
? – user362638