TQObjectCleanupHandler Class

Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# TQObjectCleanupHandler Class Reference

The TQObjectCleanupHandler class watches the lifetime of multiple TQObjects. More...

`#include <ntqobjectcleanuphandler.h>`

Inherits TQObject.

List of all member functions.

## Public Members

- TQObjectCleanupHandler ()
- ~TQObjectCleanupHandler ()
- TQObject * add ( TQObject * object )
- void remove ( TQObject * object )
- bool isEmpty () const
- void clear ()

## Detailed Description

The TQObjectCleanupHandler class watches the lifetime of multiple TQObjects.

A TQObjectCleanupHandler is useful whenever you need to know when a number of TQObjects that are owned by someone else have been deleted. This is important, for example, when referencing memory in an application that has been allocated in a shared library.

Example:

        class FactoryComponent : public FactoryInterface, public TQLibraryInterface
        {
        public:
            ...

            TQObject *createObject();

            bool init();
            void cleanup();
            bool canUnload() const;

        private:
            TQObjectCleanupHandler objects;
        };

        // allocate a new object, and add it to the cleanup handler
        TQObject *FactoryComponent::createObject()
        {
            return objects.add( new TQObject() );
        }

        // TQLibraryInterface implementation
        bool FactoryComponent::init()
        {
            return true;
        }

        void FactoryComponent::cleanup()
        {
        }

        // it is only safe to unload the library when all TQObject's have been destroyed
        bool FactoryComponent::canUnload() const
        {
            return objects.isEmpty();
        }

See also Object Model.

## Member Function Documentation

### TQObjectCleanupHandler::TQObjectCleanupHandler ()

Constructs an empty TQObjectCleanupHandler.

### TQObjectCleanupHandler::~TQObjectCleanupHandler ()

Destroys the cleanup handler. All objects in this cleanup handler will be deleted.

### TQObject * TQObjectCleanupHandler::add ( TQObject * object )

Adds object to this cleanup handler and returns the pointer to the object.

### void TQObjectCleanupHandler::clear ()

Deletes all objects in this cleanup handler. The cleanup handler becomes empty.

### bool TQObjectCleanupHandler::isEmpty () const

Returns true if this cleanup handler is empty or if all objects in this cleanup handler have been destroyed; otherwise return false.

### void TQObjectCleanupHandler::remove ( TQObject * object )

Removes the object from this cleanup handler. The object will not be destroyed.

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.