开发者

help with mixing widget painting and UDP data transfers in a multi-threaded context

开发者 https://www.devze.com 2022-12-21 10:20 出处:网络
Here is what I need to do. -I receive log data through a udp connection -I stack relevant data in a qlist

Here is what I need to do.

-I receive log data through a udp connection -I stack relevant data in a qlist -I have a timer running in the main thread that, on timeout, unstacks this data, updates some arrays then calls widget->update -The widget re-implements paintEvent and uses these arrays to draw charts.

What would be the best way to do this in order to not have any bugs.

this task is basically three processes, two of which are done in the main thread

1-I have a qthread that asks for and receives开发者_如何学C log through udp packets. This thread also stacks the data in a qlist.

2-I have a qtimer that on timeout, unstacks these events, preps the chart arrays and then calls update

3-I have a reimplementation of the paintEvent method on that widget.

I have mutexes to synchronise and protect data. Is this a bad way of doing it? Some suggestion for a "SAFE" way of doing would be appreciated.

On a side note the paintEvent is dont on a customwidget which is inside my mainwindow. I do have a second thread (concurent function) that periodically refreshes some data then emits a signal to update label fields that are outside the custom widget but inside the mainwindow. could this have a bad side effect on everything?


Overall, I think you've got the foundation for a solid program. The only suggestion I might make is to move task #2 to its own thread also. You can take advantage of the fact that you can draw on a QImage outside of the main UI thread to prep the chart arrays in a different thread. This would remove the biggest potential bottleneck to UI responsiveness from your code, and wouldn't add much more to the complexity, since you already have threads in your program. The updating on QTimer could work there just as well. When a new image is ready, you could send it either via signal or via posted event to your UI, which could then copy the image and update its display.

0

精彩评论

暂无评论...
验证码 换一张
取 消