Results 1 to 4 of 4

Thread: Signals/slots timeout

  1. #1
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Signals/slots timeout

    When you connect a oneshot signal to a slot, you may often want the connection to have a timeout that calls a different slot/function if the original signal never arrives. Does anyone know of a good clean way to write this without having to create another QTimer instance and another connection to manage?
    Software Engineer



  2. #2
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Thanks
    43
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Signals/slots timeout

    Quote Originally Posted by gfunk View Post
    When you connect a oneshot signal to a slot, you may often want the connection to have a timeout that calls a different slot/function if the original signal never arrives. Does anyone know of a good clean way to write this without having to create another QTimer instance and another connection to manage?
    Why would the timer signal "never arrive"? My understanding is that it will always arrive... it just may be late if processing loop is busy. If late is a problem, you could use QTime.start(), QTime.ellapsed() to check. If you are worried that the single-shot timer signal may somehow be discarded, you could go for a multi-shot timer, and just stop it after the first successful timeout.

  3. #3
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Signals/slots timeout

    Yes... I could do that. I guess what i'm looking for is a way to abstract out the details of using a QTime. something simple like connect(this, signal, this, slot-function, slot-function-if-timed-out, timeout value)
    Software Engineer



  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signals/slots timeout

    Something like the following?

    Qt Code:
    1. QTimer::singleShot(timeout_value, this, SLOT(on_timeout()))
    To copy to clipboard, switch view to plain text mode 

    In case you're worrying that a timer may be late I can say that on most common systems you can do nothing about it as the systems are rarely real-time systems that guarantee response times (neither Windows nor MacOS is a real-time system).

Similar Threads

  1. QHttp Timeout?
    By musaulker in forum Newbie
    Replies: 4
    Last Post: 25th February 2010, 09:43
  2. signals/slots across threads
    By high_flyer in forum Qt Programming
    Replies: 9
    Last Post: 12th March 2007, 23:56
  3. events interacting with signals/slots
    By gunhelstr in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2006, 12:30
  4. Signals/Slots stopped working
    By Jimmy2775 in forum Qt Programming
    Replies: 8
    Last Post: 31st March 2006, 21:11
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.