문제

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