2

I am making a GUI where I have multiple forms on QStackedWIdget. Now I want the data in these forms to be updated as and when available. The data will be recieved through RTI DDS. Can some one suggest me some examples or links where the GUI data is updated from Non GUI thread.

Thank You.

Sid411
  • 703
  • 2
  • 9
  • 25

1 Answers1

2

You have several options at your disposal. I will explain the one that seems to suit your situation best, as far as I can assess from your question.

First you need to know that on the subscriber side, there are three different possible kinds of interaction between your application and the DDS DataReaders: polling, listeners and waitsets. Polling basically means that your application queries the DataReader when it deems necessary, for example at a fixed rate. Using listeners means that your application provides the middleware with some callback functions which get invoked whenever new data has arrived. Waitsets are similar to a socket select, where your application thread is blocked until data arrives, or a time-out occurs -- typically followed by an action to access the DataReader.

For GUI applications, it is common to use a polling mechanism as opposed to a listener approach that you are probably using. In stead of reading the data as it arrives, and immediately updating the GUI widgets, you can let your GUI read or take data from the DataReaders at a fixed rate, for example at 5 Hz.

With that approach, you take control over when you access DDS and you can do it at the exact rate required, no matter how fast the data gets updated inside your DataReader. Additionally, your question of data being updated by a non-GUI thread is resolved, because you access the DDS DataReader from your own context.

A potential disadvantage of using polling could be that the updating of the widgets happens with some delay, for example if you poll at 5 Hz, your maximum extra delay will be 200 msec. That is usually not a problem for GUI applications though.

Reinier Torenbeek
  • 16,669
  • 7
  • 46
  • 69
  • Some data which we are processing needs to be handled at real time. A delay in handling critical data will affect our application. So please suggest any better solution than polling. – Sid411 Jul 25 '13 at 06:18
  • For data that requires high responsiveness, you could use a waitset, which works like a socket `select`. Your thread blocks until data becomes available. When it unblocks, you can read or take the data. However, the nature of this data does not sound like your typical GUI data. Are you sure you want to do this kind of real-time handling in a GUI application? – Reinier Torenbeek Jul 25 '13 at 09:27
  • Yes it is not a GUI application. GUI is only for displaying data that we are going to recieve from field. There will be one thread for GUI which will be updating the data recieved. – Sid411 Jul 25 '13 at 09:42
  • In that case, you could also consider separating this into two processes: one process to display data (using polling), another process to handle data at real-time (using waitsets or listeners). – Reinier Torenbeek Jul 25 '13 at 09:52
  • Thanks for the help. By the way which one is preferable Waitsets or Listeners? – Sid411 Jul 25 '13 at 10:00
  • 1
    Waitsets and listeners have similar characteristics, the right choice depends on the nature of your data. Typically, listeners are used if the data is more event-driven (aperiodic). For data that gets updated regularly (at high rates), waitsets tend to be more appropriate, since they decouple your application better from what happens on the databus. Often, it does not make much of a difference which of the two you use.By the way, since you are new here, make sure to check out the help section, in particular about [voting for and accepting answers](http://stackoverflow.com/help/someone-answers) – Reinier Torenbeek Jul 25 '13 at 10:12