PDA

View Full Version : Constant GUI updating / Main loop



BeautiCode
26th March 2015, 22:31
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.

jefftee
27th March 2015, 00:41
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.

anda_skoa
27th March 2015, 07:36
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,
_

BeautiCode
27th March 2015, 18:01
I've figured out how to do it with signals/slots, but thanks!