Results 1 to 4 of 4

Thread: Constant GUI updating / Main loop

  1. #1
    Join Date
    Mar 2015
    Posts
    24
    Qt products
    Qt5
    Platforms
    Windows

    Default Constant GUI updating / Main loop

    I want to develop a program in qt that constantly updates a TextEdit box.
    To be more specific, an IRC client. It would need to constantly append something to the textbox as the connection is open with QTCPSocket.
    I'm not sure how to update the textbox without some sort of event happening (clicking a button). It'd need to keep a constant display of the packets the client is receiving, open while also being able to click other buttons to send chat messages, etc. So I don't think I can be stuck in a single function using a while loop.

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Constant GUI updating / Main loop

    So don't use a while loop. Use QTcpSocket::readyRead() to be informed when you have received data on the socket. QTcpSocket::readAll() into a buffer and strip out any complete lines (ending with "\n" perhaps) from the front of the buffer and insert the text info your QTextEdit.

    You should use a buffer that persists across multiple readyRead()'s because you may have an incomplete line of data in the buffer when the next readyRead() is fired.

    As far as sending text, presumably you will connect a QPushButton::clicked() signal to a slot and then can send the data, etc.

    All of what you are attempting to do is very event driven, will not require polling, a timer, or a separate thread, etc.

    Have you started coding yet? If not, just jump right in, it should be pretty straight forward. If you have started and are running into problems, then post your code and tell us what is happening, etc.

    Good luck.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Constant GUI updating / Main loop

    Quote Originally Posted by BeautiCode View Post
    I'm not sure how to update the textbox without some sort of event happening (clicking a button).
    You don't need to update without an event happening, because you only have something to update with when an event happened.

    Data from the IRC server will not just magically appear in some variable, it arrives through the network connection.
    Which is an event driven data source.

    Cheers,
    _

  4. #4
    Join Date
    Mar 2015
    Posts
    24
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Constant GUI updating / Main loop

    I've figured out how to do it with signals/slots, but thanks!

Similar Threads

  1. How to access main loop
    By roseicollis in forum Newbie
    Replies: 6
    Last Post: 22nd December 2014, 10:22
  2. Updating QGLWidget in Qt from Main Window
    By mcodesmart in forum Qt Programming
    Replies: 0
    Last Post: 15th May 2014, 16:20
  3. Main loop thread loop communication
    By mcsahin in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 16:31
  4. main loop
    By dusza in forum Qt Programming
    Replies: 10
    Last Post: 6th June 2009, 17:29
  5. Main Thread Event loop
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2007, 12:10

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.