Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Qt to read a file and display it quickly?

Tags:

file

qt

I have to use Qt show the context of a file, whose size is 70M, but is so slow that it takes several minutes to display.

QFile file("farey.txt");
    file.open(QFile::ReadOnly | QFile::Text);
    QTextStream ReadFile(&file);
    while (!ReadFile.atEnd()) {
        QString line = ReadFile.readLine();
        ui->Output->append(line);
    }
    file.close();

Output is TextEdit, can anyone give me some help to make it faster?

Can I use Qt to dispatch a default system editor to open the file??

like image 261
tian tong Avatar asked Mar 15 '23 15:03

tian tong


1 Answers

If you want to display your file as plain text, the widget QPlainTextEdit is better then QTextEdit. It is optimized to handle large documents, for example see QTextEdit vs QPlainTextEdit

QTextEdit is an advanced WYSIWYG viewer/editor supporting rich text formatting using HTML-style tags.

QTextEdit can display images, lists and tables.

QPlainTextEdit is an advanced viewer/editor supporting plain text.

QPlainText uses very much the same technology and concepts as QTextEdit, but is optimized for plain text handling.


It is possible to open a file by default system file handler using QDesktopServices, for example:

QDesktopServices::openUrl(QUrl::fromLocalFile("file_path"));
like image 75
Orest Hera Avatar answered Apr 02 '23 03:04

Orest Hera