QTextEdit freeses



  • Hi

    I have QTextEdit and file which size is ~1 GB.

    As I read this file from the stream , and append readed data into
    the QTextEdit in main thread , the main gui event loop freezes ,
    and QTextEdit freezes also , so user feel sad.

    As far as I understand the problem is in append function who works too long.

    As I move readAll and append into another thread , program crashes by obvious
    reason - two threads (GUI thread and thread-appender) trys to work with QTextEdit simulteneously.

    I can't move QTextEdit from main thread into the thread-appender , becouse it's GUI object ,
    and so he needs GUI event loop.

    So my question is : how to avoid main event loop ( and my widget ) freezing ,
    during the large file loading into QTextEdit.

    Is exists probably advanced text edit widget , who allow reading in other thread ?

    Or may be exsists the way to isolate QTextEdit from main event loop temporarily ,
    and avoid problem with simultaneous access ?

    Or may be exists in Qt the correct , standard way to synchronize access to GUI widget
    from my thread and event loop.

    A bit of code , just to clarify

    @
    QTextStream in ( file ) ;
    QTextEdit *textEdit_ ;

    Qstring buf = in. readAll( ) ;
    textEdit_ -> append( buf ) ;
    @

    Thanks.



  • You can use a thread to load the file contents (lines 1 and 4 in your example), and only show progress information in the main thread. The question whether 1GB of text makes sense in a text edit field is independent of that approach :-)



  • Good idea. Maybe it works


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.