Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTime default initialization
Forum Updated to NodeBB v4.3 + New Features

QTime default initialization

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 704 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    The178
    wrote on last edited by
    #1

    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
    0_1561678631546_49bef6c8-2bed-4a64-94bd-bea76b14af7e-image.png
    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 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?

    JKSHJ 1 Reply Last reply
    0
    • T The178

      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
      0_1561678631546_49bef6c8-2bed-4a64-94bd-bea76b14af7e-image.png
      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 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?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #2

      @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 is QTime. Just be aware that QTime != QTimer. See also QElapsedTimer for completeness: https://doc.qt.io/qt-5/qelapsedtimer.html

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      T 1 Reply Last reply
      5
      • JKSHJ JKSH

        @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 is QTime. Just be aware that QTime != QTimer. See also QElapsedTimer for completeness: https://doc.qt.io/qt-5/qelapsedtimer.html

        T Offline
        T Offline
        The178
        wrote on last edited by
        #3

        @JKSH Ah, gotcha! Thank you, yes I see that this would cause more trouble than needed, I'll look into renaming it.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved