Results 1 to 13 of 13

Thread: implemet a timer

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: implemet a timer

    Hi,

    Not a good aproach to use an infinite loop and breaking it on this way.

    Use 2 QTimers:
    -First one that will fire ever X ms(depending on Baud Rate you have to calculate this) and will take a look if there is data avaiable.
    When the first timer fires, take a look if there is data to read, if there isn't, you have to check if the secon timer is started, if not started, start it.

    The second one will fire if you have not readed any data in 10 seconds. This will be a singleShot timer. When it fires, stop the first timer.
    Òscar Llarch i Galán

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: implemet a timer

    wont an infinite loop be necessary in this case...where we have to do something until a condition satisfies..which means we dont know until this condition will come true..i dont know why everyone is so against using 'break' in a loop..its just an equivalent of JMP in assembly which is probably the most common instruction in assembly

  3. The following user says thank you to talk2amulya for this useful post:

    adamatic (17th February 2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: implemet a timer

    Yes,

    You do work until some case is done.
    But having data on serial port is slower than every iteration of the bucle, so you will waste too much time by doing nothing.
    Using a timer with a time calculated to satisfy the Baud Rate will be a more elegant way.
    Òscar Llarch i Galán

  5. The following user says thank you to ^NyAw^ for this useful post:

    adamatic (17th February 2009)

  6. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: implemet a timer

    makes sense..thanks for clearin that up..i didnt know abt the baud rate and stuff

  7. #5
    Join Date
    Jan 2009
    Posts
    54
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: implemet a timer

    I have finally decided use the idea of use 2 timers, checking every second the input port and stop both timers when it receives datas, and if there arent datas after 10 seconds go to another slot and stop them.

    Thank you very much to all the answers.

Similar Threads

  1. how to enable a timer in a non-gui thread?
    By zeopha in forum Qt Programming
    Replies: 3
    Last Post: 5th August 2008, 09:29
  2. Thread, Timer and Socket. Comuication problem
    By ^NyAw^ in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2008, 16:48
  3. Timer for application
    By Zergi in forum Qt Programming
    Replies: 3
    Last Post: 26th December 2007, 22:21
  4. Thread(s) and socket, timer slots
    By stephdev1965 in forum Qt Programming
    Replies: 1
    Last Post: 8th November 2006, 14:04
  5. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36

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.