PDA

View Full Version : Paintevent and update



csvivek
24th March 2008, 05:58
Hi,

I have a requirement, wherein i receive data from a socket, to be continuously drawn on the widget.
The socket is pumping data with the worst case speed of 1ms.

I have a thread to receive the data, after reception i copy the data into the widget's member to be drawn, then i call the update() function.

here i have two problems :confused:
1.Update requires some time to finish its job, but by this time there is a possibility of receiving new data.
here i may miss soem data from socket or painting for that set is incomplete ...

2.For the sake of optimization, its said that "Calling update() several times normally results in just one paintEvent() call." so in this case what happens to the data which is to be drawn for each update?
i.e. lets say i received 4 data which would result in calling 4 updates and ideally the widget was supposed to be redrawn 4 times.
but due to this optimization i may have only the last data read.

Can anybody suggest what needs to be done for this, i think i need to implement a buffer, but i dont know how to pass this info for PaintEvent.:crying:

Thanks in advance :)

Wim
25th March 2008, 08:09
1. If you have a separate thread receiving data, you just have to make sure that tread checks your socket often enough, right?

2. If you copy data to the widget, is the old data overwritten or added to existing data? If it is added, you already have all data, so no need to buffer. If it is overwritten, and your data has not been drawn on the widget yet, your data will be lost.

3. Update combines all drawing into one paint event, so everything will be drawn. If you have an animation type of widget that erases the previous data, than you are right that in your example of 4 data received, and combined in one paint event, you will see only the last data. In that case you can try if using the QWidget::repaint () function solves your problem.

4. If repaint() is slower then your data stream, and you don't mind seeing a delay between the received data and the widget drawing, you need to implement a buffer class that calls the repaint function as long as there is data that needs to be shown.

Wim