PDA

View Full Version : QTimer - too many in application??



db
28th March 2008, 13:40
I'm having a problem with QTimer and hope someone can set me straight. I've been through the posts and haven't found a similar situation.

I have a QMainWindow application that has 15 menu selections. Each of these menu selections starts a new QDialog widget that contains a QTableView with an associated data model. The responsibility of each of these dialog widgets is to update the model with data from a shared memory segment that is always changing.

Each dialog widget has a QTimer associated with it since I want to update the data at a couple of different time rates. Some are 1 sec others are .5 sec. When the widget is shown the timer is started and when the widget is minimized the timer is stopped.

The problem is that when I have several (5) of the widgets displayed (all these have 1 sec timers) some update at 1 sec, others update at odd intervals like 4, 6, 7, 9, (...etc) seconds.

Is there such a thing as too many timers in a QT application?
Could the timers be interferring with each other?
Is there a better (simpiler) approach that I'm missing?
Would it be better to start each of these dialogs in their own thread (thats a lot of threads)?

Any help/discussion would be helpful. Thanks in advance.

yogeshm02
28th March 2008, 16:47
One possibility is that updation of the model is proving to be too costly. Have you checked which part of your code is slowing the things down?
If i've understood you correctly, then each of the table view has a separate model and the model refreshes its data from the shared data source.
If the problem is about refreshing the model, then you can create a custom model which manage the shared data source (in other words, convert the shared data object into a model) and then share that same model object everywhere.

db
28th March 2008, 17:59
Thanks for the input. However the problem is not in getting the correct data, that works fine and when the time goes off the correct data is displayed. Access is via a memory pointer into linux shared memory structure.

The actually problem is in getting all the timers to timeout at their set time (1 sec). I agree it must be slowing it down, but not sure why.

yogeshm02
28th March 2008, 19:26
Timer won't fire at correct time if your app is doing expensive operations. Number of timers is not the root cause of delay. Use qtime or something similar to check which function is consuming more time.

db
31st March 2008, 16:12
OK. I'll give it a try