← Back to Docs
  • index.html
  • Clayground
  • Clayground.Common
  • ClayStopWatch
  • Clayground 2025.2
  • ClayStopWatch QML Type

    A simple stopwatch for measuring elapsed time. More...

    Import Statement: import Clayground.Common

    Properties

    Signals

    Methods

    Detailed Description

    ClayStopWatch provides millisecond-precision timing for performance profiling and gameplay mechanics. It wraps Qt's QElapsedTimer for high-resolution timing.

    Example usage:

    import Clayground.Common
    
    ClayStopWatch {
        id: timer
        onElapsedChanged: console.log("Elapsed:", elapsed, "ms")
    }
    
    Component.onCompleted: {
        timer.start()
        // ... do some work ...
        timer.stop()
    }

    Property Documentation

    elapsed : int

    The elapsed time in milliseconds since the last start().

    This value is updated when stop() is called. While the stopwatch is running, this property holds the value from the previous stop() call (or 0 if never stopped).


    running : bool

    Whether the stopwatch is currently running.


    Signal Documentation

    void elapsedChanged()

    Emitted when the elapsed time is captured (after stop()).

    Note: The corresponding handler is onElapsedChanged.


    void runningChanged()

    Emitted when the running state changes.

    Note: The corresponding handler is onRunningChanged.


    Method Documentation

    void start()

    Starts or restarts the stopwatch from zero.

    Calling start() while already running restarts the timer.


    void stop()

    Stops the stopwatch and captures the elapsed time.

    After calling stop(), the elapsed property contains the time in milliseconds since start() was called.