Results 1 to 2 of 2

Thread: QDateTime .setTime problem

  1. #1
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QDateTime .setTime problem

    Hi, i''m workin with QDateTime and it's happen the following problem:

    in mainwindow.h, i put:
    QDateTime globalTime;

    in mainwindow.cpp, in constructor:
    globalTime.setTime(QTime(0,0));
    qDebug() << "Time: " << globalTime.toString("mm:ss:zzz") << ";";
    ----> this debug print: Time: "" ;

    I have a timer, that count to 50 ms and do:
    globalTime = globalTime.addMSecs(50);
    qDebug() << "Time: " << globalTime.toString("mm:ss:zzz") << ";";
    ------> In this debug, i get:
    Time: "" ;
    Time: "" ;
    (...)
    Time: "" ;
    Time: "" ;
    Time: "00:01:200" ;
    Time: "00:01:250" ;
    Time: "00:01:300" ;
    Time: "00:01:350" ;
    Time: "00:01:400" ;
    (...)

    -----------------------------------------------------------------------------------------------
    If in constructor, i switch globalTime.setTime(QTime(0,0)); to globalTime.setTime_t(0); ,
    the qDebug() << "Time: " << globalTime.toString("mm:ss:zzz") << ";";
    print: Time: "00:00:000" ; and every 50ms i get the time.

    So, i would like understand why the first way only show the time after 1:200 seconds.



    Bye, Sérgio Silva
    Last edited by sergiofil; 28th April 2011 at 16:21.

  2. #2
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDateTime .setTime problem

    bool QDateTime::isValid () const
    Returns true if both the date and the time are valid; otherwise returns false.
    Not sure why it happens after 1 second , but in order to operate with QDateTime correctly , both time and data must be set. You've set the time only with setTime method and in case of latter , setTime_t has set the time and year to the 03:00:00 1970 (as it said in the documentation) So you've got both set and ready to go.

Similar Threads

  1. Milliseconds from QDateTime
    By scamE in forum Qt Programming
    Replies: 3
    Last Post: 12th September 2010, 19:46
  2. QDateTime problem
    By Majdi in forum Newbie
    Replies: 11
    Last Post: 28th January 2009, 15:57
  3. Problem with comparing two QDateTime objects
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2008, 11:27
  4. QDateTime fromString
    By mklieber in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2008, 21:15
  5. QDateTime without Day
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 16th February 2006, 11:42

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.