Results 1 to 3 of 3

Thread: QDateTime.fromMSecsSinceEpoch creates an invalid instance

  1. #1
    Join Date
    Jun 2016
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question QDateTime.fromMSecsSinceEpoch creates an invalid instance

    Fore the following code snippet
    Qt Code:
    1. quint64 t = 1464808943000;
    2. dt.fromMSecsSinceEpoch(t);
    3. if (dt.isValid())
    4. cout << "Valid" << endl;
    5. else
    6. cout << "Not valid" << endl;
    7. QString format = QString("yyyy.MM.dd.hh.mm.ss");
    8. QString timeStamp = dt.toString(format);
    9. cout << timeStamp.toStdString() << endl;
    To copy to clipboard, switch view to plain text mode 

    The output is
    Not Valid,
    (empty string)

    I am convinced that the number is valid. Entering it in http://www.epochconverter.com/ generates a valid date-time Wed, 01 Jun 2016 19:22:23 GMT.

    Using Qt 4.8 on Wincows 8, compiling with Visual Studio 2010.

    What am I doing wrong?

    Michael

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QDateTime.fromMSecsSinceEpoch creates an invalid instance

    Try dt = QDateTime::fromMSecsSinceEpoch(t); QDateTime::fromMSecsSinceEpoch() is a static member function.
    Last edited by jefftee; 18th June 2016 at 06:06.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3
    Join Date
    Jun 2016
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QDateTime.fromMSecsSinceEpoch creates an invalid instance

    Silly me
    Thank you!

Similar Threads

  1. fromMSecsSinceEpoch does not work as expected
    By nuliknol in forum Qt Programming
    Replies: 3
    Last Post: 28th January 2015, 06:59
  2. Does Qt creates any thread for handling Events?
    By blue_sky in forum Qt Programming
    Replies: 3
    Last Post: 6th September 2013, 08:51
  3. Building Qt 5.0 from source creates many errors
    By astodolski in forum Installation and Deployment
    Replies: 0
    Last Post: 23rd January 2013, 21:17
  4. QDateTime Invalid
    By FreePascal in forum Newbie
    Replies: 2
    Last Post: 7th June 2009, 19:35
  5. Loading DLL that creates GUI.
    By The Storm in forum Qt Programming
    Replies: 11
    Last Post: 3rd December 2008, 18:19

Tags for this Thread

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.