Gustavo Litovsky
Gustavo Litovsky

Reputation: 2487

QT's fromTime_t from QDateTime doesn't work

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?

Upvotes: 4

Views: 8415

Answers (2)

Kirween
Kirween

Reputation: 1538

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);

Upvotes: 8

RA.
RA.

Reputation: 7777

Your code doesn't use the static function correctly. Try this instead:

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

Upvotes: 3

Related Questions