×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    27

    Problem with QDateTime setTime_t?

    Hello,

    I've been banging my head with this for a while, I'm sure it will turn out to be a silly thing but I just can't figure it out by myself.

    It seems that QDateTime's setTime_t doesn't behave like I would expect. See the code below:

    QDateTime t1 = QDateTime::fromString("09:30", "hh:mm");
    QDateTime t2;
    t2.setTime_t(t1.toTime_t());
    QCOMPARE(t1, t2);

    And the outcome is:

    Actual (t1): 1900/01/01 09:30:00.000[local time]
    Expected (t2): 2106/02/07 08:28:15.000[local time]

    I was expecting t1 and t2 to be the same. Can anybody spot what's wrong? I'm using Qt 4.6.2 on Mac OS X 10.6.

    Thanks in advance!

    Bale

  2. #2
    Registered User
    Join Date
    Dec 2004
    Posts
    27

    Re: Problem with QDateTime setTime_t?

    Never mind. I'm using a test date in year 1900 and time_t counts time starting from 1970...

  3. #3
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Problem with QDateTime setTime_t?

    Note that there is a copy constructor:
    Code:
    QDateTime t1 = QDateTime::fromString("09:30", "hh:mm");
    QDateTime t2(t1);
    QCOMPARE(t1, t2);

Similar Threads

  1. STLPort namespace issue
    By yickhong in forum Open C/C++
    Replies: 0
    Last Post: 2009-04-09, 08:54
  2. SyncML link problem
    By samuel_ in forum Symbian
    Replies: 4
    Last Post: 2009-03-27, 08:02
  3. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  4. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 08:56
  5. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×