On this page

Utils::GuardedObject Class

template <typename T> class Utils::GuardedObject

The GuardedObject class owns a heap-allocated object and deletes it when the shutdown guard is destroyed. More...

Header: #include <shutdownguard.h>

Detailed Description

This is the preferred way to hold a process-lifetime singleton, as it avoids a manual shutdownGuard() connection. Typically used as a function-local static:

MyThing &myThing()
{
    static GuardedObject<MyThing> theMyThing; // created on first use,
    return *theMyThing;                       // deleted at shutdown
}

Construct it from constructor arguments (as above) or from an existing object pointer (GuardedObject<MyThing>{new MyThing(...)}).

See also Utils::shutdownGuard().

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.