Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT's fromTime_t from QDateTime doesn't work

Tags:

c++

qt

I tried using QDateTime's fromTime_t as follows:

QDateTime t;
time_t elapsedTime;
t.fromTime_t(elapsedTime);

The result is that nothing is assigned to the QDateTime object. However, using the function setTime_t does work (this one isn't static). Is something going on here I'm missing?

like image 749
Gustavo Litovsky Avatar asked Jan 14 '23 16:01

Gustavo Litovsky


1 Answers

fromTime_t is static and returns a QDateTime, so you have to use it like this:

    time_t elapsedTime;
    QDateTime t(QDateTime::fromTime_t(elapsedTime));

or you can do

    time_t elapsedTime;
    QDateTime t;
    t.setTime_t(elapsedTime);
like image 70
Kirween Avatar answered Jan 26 '23 04:01

Kirween