Thread: Timer in C++

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    107

    Timer in C++

    In VB6 we had a control that you dragged/dropped onto a form and you could set the time interval, any code inside the timer would be fired etc.

    What is the equivalent way to do this in C++?

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Yes, but not in a drag-and-drop way. You'll need to write the code for it. Check out this link alarm
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    257
    Quote Originally Posted by jim_0 View Post
    In VB6 we had a control that you dragged/dropped onto a form and you could set the time interval, any code inside the timer would be fired etc.

    What is the equivalent way to do this in C++?
    That depends entirely on what GUI-Framework you're using. MFC will do this differently than Qt, which in turn does it differently than wxWidgets, etc.
    Last edited by antred; 09-12-2014 at 09:30 AM.

  4. #4
    Registered User
    Join Date
    Nov 2013
    Posts
    107
    Sorry, I know it done in code I was just using the VB6 example to show exact what I wanted.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Elkvis View Post
    Yes, but not in a drag-and-drop way. You'll need to write the code for it. Check out this link alarm
    The first part of the post was good. But the second one was not.
    All you did was provide a link to some API function available only in linux. Way to go.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Elysia View Post
    ...available only in linux. Way to go.
    No. Alarm is a Posix function. Most modern operating systems, including Windows, support Posix.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Windows does not support posix.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Elysia View Post
    Windows does not support posix.
    I agree with this. But, some Windows Compilers support some parts of Posix would be correct.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Elysia View Post
    Windows does not support posix.
    You are misinformed. POSIX and UNIX Support in Windows - TechNet Articles - United States (English) - TechNet Wiki
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Sorry, but your argument is full of holes. Though the exact information is hard to come by (thank you, Microsoft, for making it so hard to decipher what's written on your pages), it goes something like this:

    Microsoft implemented POSIX 1.0 for older operating systems (pre XP).
    POSIX was removed as of XP and was made available as a standalone download.
    The standalone download was then deprecated (extended support running out this year).
    It was also made available in some forms in server and business operating systems as SUA. Again, this is business, so Enterprise versions and up.
    SUA was deprecated in Windows 8.
    SUA was completely removed in 8.1.

    Source: https://superuser.com/questions/4953...mplement-posix (and wikipedia)

    So no, unless you somehow use some emulation library, POSIX is not supported by Windows.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Dec 2011
    Location
    Namib desert
    Posts
    94
    Me no speak microsoft .... but you could try the cross-plarform development environment Qt which is a much beloved and generally used environment for Linux. In a windows environmnet you then have to install MINGW in order to get a more or less GNU-compatible compiler. Still, MINGW does not fully support POSIX.

    Another GNU-compatible compiler is from Cygwin, as far as I know it does support Posix.

    Anyway, there are always differences between Linux and Windows for example if you program sockets (see also https://qt-project.org/search/tag/cygwin).

    Qt supplies the Qtimer-object which should work within the windows environment.

  12. #12
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by ddutch View Post
    Me no speak microsoft .... but you could try the cross-plarform development environment Qt which is a much beloved and generally used environment for Linux. In a windows environmnet you then have to install MINGW in order to get a more or less GNU-compatible compiler. Still, MINGW does not fully support POSIX.

    Another GNU-compatible compiler is from Cygwin, as far as I know it does support Posix.

    Anyway, there are always differences between Linux and Windows for example if you program sockets (see also https://qt-project.org/search/tag/cygwin).

    Qt supplies the Qtimer-object which should work within the windows environment.
    Cygwin does indeed support Posix, but I wouldn't recommend using it. Cygwin tends to be slow (in my experience) and is intended to compile source for Unix-only programs on Windows. I don't feel that it's particularly useful for general Windows programming.

    If you want something like the timer in VB6, I would go with Qt. You can create GUI and console-based applications with Qt, and those applications can generally be rebuilt for any platform that supports Qt, with very few changes in the source.

    Thanks to Elysia for clarifying Posix support in Windows. I wasn't aware that they had removed it.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  13. #13
    Registered User
    Join Date
    Nov 2013
    Posts
    107
    Are you not meant to use QueryPerformanceFrequency/QueryPerformanceCounter. I found this that works but is there any other way?

  14. #14
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by jim_0 View Post
    Are you not meant to use QueryPerformanceFrequency/QueryPerformanceCounter. I found this that works but is there any other way?
    You can definitely do that, but you have to manage it every step of the way, polling it every so often to see if your time has elapsed. If you use something like Qt, it has an event loop that does the checking for you, and calls your code each time the timer ticks.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  15. #15
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    So nobody bothered answering his question -- just arguing about a completely unrelated issue. Helpful.

    Look into the functions defined in the ctime header, specifically time().
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 60 hz timer
    By crowe in forum Tech Board
    Replies: 18
    Last Post: 01-20-2010, 11:18 AM
  2. Timer In C
    By unmeshghosh in forum C Programming
    Replies: 10
    Last Post: 04-21-2006, 01:00 PM
  3. C++ Timer?
    By Rv5 in forum C++ Programming
    Replies: 1
    Last Post: 03-15-2006, 06:33 PM
  4. timer
    By b00l34n in forum C++ Programming
    Replies: 9
    Last Post: 04-06-2004, 08:20 AM
  5. how to set timer
    By marianne in forum C Programming
    Replies: 1
    Last Post: 02-12-2003, 10:21 PM