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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top