Results 1 to 5 of 5

Thread: QSpinBox Timer Issue

  1. #1
    Join Date
    May 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSpinBox Timer Issue

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSpinBox Timer Issue

    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?
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    May 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSpinBox Timer Issue

    This example demonstrates the problem
    Output on linux is:
    Calc Starting
    Calc Stopped
    TestSpinner::timerEvent()
    Calc Starting
    Calc Stopped
    TestSpinner::mouseReleaseEvent()


    test.zip

    Attachments got a bit screwy, just use the zip file
    Attached Files Attached Files

  4. #4
    Join Date
    Nov 2009
    Posts
    14
    Thanks
    4

    Default Re: QSpinBox Timer Issue

    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.

  5. #5
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QSpinBox Timer Issue

    Try subclassing QDoubleSpinBox, then override "timerEvent()" but don't call the base class implementation:
    Qt Code:
    1. MyDoubleSpinBox::timerEvent(QTimerEvent *event) { event->accept();}
    To copy to clipboard, switch view to plain text mode 
    This seems to solve the problem in bcollie's example above. As the old saying goes: Better late than never.

    HTH

Similar Threads

  1. timer problem(timer does not work)
    By masuk in forum Newbie
    Replies: 6
    Last Post: 14th February 2011, 05:00
  2. How to add timer delay
    By qtUse in forum Newbie
    Replies: 1
    Last Post: 12th October 2010, 18:09
  3. Timer for application
    By Zergi in forum Qt Programming
    Replies: 3
    Last Post: 26th December 2007, 22:21
  4. Timer call
    By mahe2310 in forum Qt Programming
    Replies: 1
    Last Post: 28th March 2006, 08:57
  5. Timer not timing out?
    By Mariane in forum Newbie
    Replies: 5
    Last Post: 2nd March 2006, 21:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.