Important: Please read the Qt Code of Conduct -

Cast (int)qint64 ??

  • i have a qint64 var1 = 1345830775404
    and int var2 = (int)var1; (var2 becomes 1506011756, what gives?)

    To clarify what i am trying to do is to get in an integer the seconds since 1970 January 1st
    in an application online it returns 1345830763 seconds.
    so it seems is just have to "cut off" the last 3 digits..

  • qint64 is 64 bits wide, it can store 2^32 times more values than an int (which is 32 bits wide). If you want to operate on UNIX timestamps based on the epoch, you HAVE to use at least a 64 bits integer, because they will most likely not fit in 32 bits.

  • oops just figured that i was using milliseconds instead of seconds :/ (sorry about that :$ )
    so this just did it
    @int secSince1970 = QDateTime::currentDateTimeUtc().toMSecsSinceEpoch()/1000;@

Log in to reply