Question

I want to read unicode from file and display the corresponding data in a QTextEdit.Please give me some suggestions.

Was it helpful?

Solution

Your question is a bit poor, but you need to use QFile and QTextEdit for this as follows:

QFile file("in.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    return;

QTextStream in(&file);
while (!in.atEnd())
    myTextEdit.append(in.readLine());

or if you are not dealing with a huge file and small memory, you can read the file in as a whole without reading lines and chunks:

QFile file("in.txt");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    return;

myTextEdit.setText(file.readAll());
// or setPlainText(file.readAll());

These will read the data in as unicode by default based on the documentation.

There are several ways of doing it, so this answer is just giving you some taste, and you will need to fine-tune this based on your specific scenario. You will need to add proper error handling, includes, build system files, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top