Results 1 to 7 of 7

Thread: clock() function

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default clock() function

    hi,
    I need use clock() (or similar but not QT functions!) to do this:
    Qt Code:
    1. int done =1
    2. while (done) {
    3. clearScreen()
    4. if (anyPressedKey) done=0;
    5. float posy = clock()/20;
    6. mySetPos(10, posy-40);
    7. print ("HELLO EVERY BODY ");
    8. if (posy>600) posy -= 600;
    9. }
    To copy to clipboard, switch view to plain text mode 
    I need the text go down and when it reach 600 it wait a while and restart from start point...Any hints?
    this code doesn't work. and float posy could reach its high bound.......
    Is there a way to reset and/or stop the clock() counter????
    Thanks
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: clock() function

    Quote Originally Posted by mickey
    Is there a way to reset and/or stop the clock() counter????
    No, there isn't, but you can use modulo.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: clock() function

    hi I do this and seem ok;
    Qt Code:
    1. int posy = ((int) (clock()/20)) %600;
    To copy to clipboard, switch view to plain text mode 
    But problem is that when posy reach 600, the print should be later of 5 seconds;
    I can code this:
    Qt Code:
    1. if (posy ==0)
    2. for (int i =0; i<1000; ++i) ;
    To copy to clipboard, switch view to plain text mode 
    but this has different behavior on different machines and more imposrtant: posy GOES ON......(so next print don't print at '0' point but '0' plus something...)
    Are u understanding this problem? Any hints?Thanks...
    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: clock() function

    You can use sleep() to wait 5 seconds.

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: clock() function

    thanks for fast reply;
    unser win32 there's Sleep() function that works with milliseconds. I code this:
    Qt Code:
    1. if (posy == 600 ) Sleep(10000) //10 secs;
    To copy to clipboard, switch view to plain text mode 
    But don't resolve my problem:
    I'm inside a while that catch mouse event also : Sleep block all;
    Furthermore: clock() isn't stopped; so next time print() doesn't print at '0' point but '0' + something.... nut problem? thanks.....
    ----
    additional prob:
    int posy = ((int) (clock()/20)) %600; posy is an int: so the when print at '0' and print at '1' I can see a very little jump.....a float value should be more linear...... but I read '%' works between int????
    Last edited by mickey; 10th September 2006 at 23:48.
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: clock() function

    Quote Originally Posted by mickey
    I'm inside a while that catch mouse event also : Sleep block all;
    Furthermore: clock() isn't stopped; so next time print() doesn't print at '0' point but '0' + something.... nut problem?
    You can always subtract some value from the one returned by clock(). This way you can measure time.

    Quote Originally Posted by mickey
    int posy = ((int) (clock()/20)) %600; posy is an int: so the when print at '0' and print at '1' I can see a very little jump.....a float value should be more linear...... but I read '%' works between int????
    Qt Code:
    1. double posy = ( clock() % 12000 ) / 20.0
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: clock() function

    but this has different behavior on different machines
    CLOCKS_PER_SEC macro will return how many clock ticks per second a the local system uses.

Similar Threads

  1. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  2. Qt 4.1.4 plugin QPSQL
    By jcr in forum Installation and Deployment
    Replies: 4
    Last Post: 22nd June 2006, 22:55
  3. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52
  4. Unable to execute in Debug Mode
    By Kapil in forum Installation and Deployment
    Replies: 38
    Last Post: 5th April 2006, 07:27
  5. use libs under qt4
    By raphaelf in forum Qt Programming
    Replies: 6
    Last Post: 27th February 2006, 17:59

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.