Results 1 to 6 of 6

Thread: date-time problem

  1. #1
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face date-time problem

    hello to everyone,

    i have the followign problem:

    i need to get the system date-time {i think it is done like this--> QDate myDate(QDate::currentDate())} and then i

    need a way to add minutes(!!) to this variable....

    in particular i want to make a program{actually part of a another program} that will print on a label dates&times.

    The problem is that i must print the date-time every hour.But also simulate an hour with 1 minute{i believe that i can do so with the Sleep() function}...

    so a possible output could be:
    Wed Feb 11 2007 22:09
    Wed Feb 11 2007 23:09
    Wed Feb 11 2007 00:09
    Wed Feb 12 2007 01:09
    ....
    ....

    thanks for your help

    PS:: sorry for my english...

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: date-time problem

    Is that a GUI application? You don't want to sleep() in a GUI application because that would freeze the whole application by blocking the applications event loop. You can use QTimer to perform periodic tasks.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: date-time problem

    Quote Originally Posted by jpn View Post
    Is that a GUI application? You don't want to sleep() in a GUI application because that would freeze the whole application by blocking the applications event loop. You can use QTimer to perform periodic tasks.
    i forgot to say that i am rather new to gui designs...yes it is for gui application.In theory at least i am thinking of a button that when pressed the whole application would stop until the dates are outputed to a file or label....but the problem isn't there.

    The problem is that i dont know what type to use to represent date and time so that i can have the ability to add minutes to an original time....

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: date-time problem

    Quote Originally Posted by aegis View Post
    The problem is that i dont know what type to use to represent date and time so that i can have the ability to add minutes to an original time....
    Take a look at QDateTime. It represents both date and time. It's basically a combination of QDate and QTime.

    Qt Code:
    1. QDateTime dateTime = QDateTime::currentDateTime(); // get current date and time
    2. dateTime.addSecs(60); // add minute
    3. QString str = dateTime.toString(); // the date time as a textual representation
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

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

    aegis (11th February 2007)

  6. #5
    Join Date
    Feb 2007
    Posts
    42
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: date-time problem

    thanks jpn...now i am using the qt opensource edition is it possible to create an application that will use Qt4 but it wont require the client to install the library?

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: date-time problem

    The subject has been discussed in here: Deploying Qt Applications.
    J-P Nurmi

Similar Threads

  1. time and date issues
    By boog07005 in forum Newbie
    Replies: 5
    Last Post: 20th August 2012, 15:15
  2. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  3. Replies: 16
    Last Post: 7th March 2006, 15:57
  4. Problem with pointers while using localtime() and time()
    By jamadagni in forum General Programming
    Replies: 7
    Last Post: 11th January 2006, 15:48

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.