K
K
Kirixo2019-12-06 02:30:25
Qt
Kirixo, 2019-12-06 02:30:25

Why can't text from a file be inserted into QTextEdit?

in general, I write like this, but when you run textEdit by the name code is empty, while code.txt definitely has text. what am I doing wrong?

QFile code("code.txt");
      task.open(QIODevice::ReadOnly);
      ui->code->insertPlainText(code.readAll());
   code.close();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2019-12-06
@Kirixo

QFile code("code.txt");
if (!code.open(QIODevice::ReadOnly | QIODevice::Text)){
    qDebug() << "file doesn't open";
    return ...;
}
ui->code->insertPlainText(code.readAll());
code.close();

J
Jacob E, 2019-12-06
@Zifix

Is it displayed in qDebug()? Why is there no check to see if the file was successfully opened?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question