H
H
h1_0ne2018-12-17 22:06:31
Qt
h1_0ne, 2018-12-17 22:06:31

Why doesn't reading and writing to files work in qt creator?

There is a window, in the window there is a button and a label. button code

void HelloWindow::on_pushButton_clicked()
{
QFile fileOut("data.txt");
QString name=ui->pushButton->text();
if(fileOut.open(QFile::ReadOnly | QFile::Text)){
       QTextStream stream(&fileOut);
       QString str=stream.readAll();
       ui->label->setText(str);
   }
else
    QMessageBox::information(this,"error","ERROR!");
fileOut.close();
}

There is a line in the data.txt file. Cute does not issue an error messagebox, that is, the reading happened and everything is ok with it, but the text on the label is assigned to emptiness, that is, it could not read from the file. It's the same with recording - there is no error, but the cut does not record anything. Why is this and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vreitech, 2018-12-17
@fzfx

either the file does not exist on the path that you specified, or there are no read rights to it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question