PDA

View Full Version : QSpinBox Timer Issue



bcollie
12th July 2011, 17:19
Hi,

I have an application that executes a calculation on QSpinBox::valueChanged.
This calculation takes around half a second to perform.

When a user clicks the step up button, two valueChanged events occur.

After some digging, this appears to be because the calculation takes a bit too long, causing the timer to fire. When valueChanged and the calc finishes, the spinbox receives a timerEvent followed by a mouseReleaseEvent.

Since the user did a simple click, so releasing the the mouse before the timer was due to fire, I see this as a qt bug. Surely qt should send events in chronological order, ie. mouseReleaseEvent followed by timerEvent.

Thanks
Bruce

mcosta
13th July 2011, 09:46
for long time calculation I suggest you to use QRunnable.

For me (Qt 4.7.3) the slot is called once. Are you sure you don't connected twice?

bcollie
13th July 2011, 11:38
This example demonstrates the problem
Output on linux is:
Calc Starting
Calc Stopped
TestSpinner::timerEvent()
Calc Starting
Calc Stopped
TestSpinner::mouseReleaseEvent()


6658

Attachments got a bit screwy, just use the zip file

positive_4_life
19th October 2011, 22:49
After some digging, this appears to be because the calculation takes a bit too long, causing the timer to fire. When valueChanged and the calc finishes, the spinbox receives a timerEvent followed by a mouseReleaseEvent.
Can someone confirm or deny that if a calculation takes too long, then spinbox will cause a timer to fire?

Because I'm having a similar issue where, where the valuechanged() signal is being emitted thrice, once by the actual mousepressevent when clicking spinbox inc/dec, and twice due to a timerevent possibly due to large calculations taking place.

norobro
20th October 2011, 03:03
Try subclassing QDoubleSpinBox, then override "timerEvent()" but don't call the base class implementation:

MyDoubleSpinBox::timerEvent(QTimerEvent *event) { event->accept();}This seems to solve the problem in bcollie's example above. As the old saying goes: Better late than never.

HTH