QTime default initialization
-
Hey, curious about something (I'm new to Qt and am taking over someone else's code). I've noticed that they create a new QTime (static) object
static QTime timer
but they don't initialize it. Then, few lines down (bunch of functional calls), it does
if (timer.isNull())) {timer.start(); //else if ...
.
I read about QTime default constructor
and so it looks like to me, the way this code was written declares all new variables at the top of the function as done by practice, then does a bunch of calls that actually do take up some execution time, and only then starts the timer by implementingif(timer.isNull()) {timer.start();}
because it will be set to null by default since the person didn't initialize it. Is this correct? -
@The178 said in QTime default initialization:
it looks like to me, the way this code was written declares all new variables at the top of the function as done by practice, then does a bunch of calls that actually do take up some execution time, and only then starts the timer by implementing
if(timer.isNull()) {timer.start();}
because it will be set to null by default since the person didn't initialize it. Is this correct?Yep, you got it. See also https://doc.qt.io/qt-5/qtime.html#start
Note: It took me a while to understand your post because the variable name is
timer
but the class isQTime
. Just be aware thatQTime
!=QTimer
. See alsoQElapsedTimer
for completeness: https://doc.qt.io/qt-5/qelapsedtimer.html