Results 1 to 2 of 2

Thread: accesing QTextEdit from thread

  1. #1
    Join Date
    Dec 2008
    Posts
    17
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default accesing QTextEdit from thread

    Why everytime I try to call TextEdit->insertPlainText(...) from inside a thread it gives me runtime erorr? It gives this only in debug mode... release works fine.
    Last edited by msmihai; 8th December 2008 at 11:15.

  2. #2
    Join Date
    Oct 2008
    Location
    Brazil, Sao Paulo - SP
    Posts
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: accesing QTextEdit from thread

    You shouldn't be calling GUI methods from outside the GUI thread, doing this is totally bug-prone.

    One approach to solve your problem is to use Qt signals/slots mechanism. When emitting a signal to a object from another thread, the default behaviour is to enqueue the slot execution at the receiver thread event queue.

    In short, your thread (or whichever object from another thread that is doing the call) could emit a signal , i.e. addToTextEdit(const QString&), that is connected to the QTextEdit::insertPlainText(const QString&) slot. This way, the QTextEdit text will only be changed on the QTextEdit owner thread (probably the QApplication one).

Similar Threads

  1. Accesing widgets from separate thread
    By msmihai in forum Qt Programming
    Replies: 2
    Last Post: 8th December 2008, 11:48
  2. QT + OpenGL + Thread => aaaahhhhh !
    By anthibug in forum Qt Programming
    Replies: 7
    Last Post: 26th July 2008, 13:36
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  4. Replies: 10
    Last Post: 20th March 2007, 22:19
  5. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.