Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    QTextEdit freeses

    General and Desktop
    2
    3
    1596
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Z
      zerg2011 last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • M
        miroslav last edited by

        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 :-)

        Mirko Boehm | mirko@kde.org | KDE e.V.
        FSFE Fellow
        Qt Certified Specialist

        1 Reply Last reply Reply Quote 0
        • Z
          zerg2011 last edited by

          Good idea. Maybe it works

          1 Reply Last reply Reply Quote 0
          • First post
            Last post