返回介绍

QObjectCleanupHandler Class

发布于 2019-10-04 15:01:48 字数 2673 浏览 977 评论 0 收藏 0

The QObjectCleanupHandler class watches the lifetime of multiple QObjects. More...

#include <qobjectcleanuphandler.h>

Inherits QObject.

List of all member functions.

Public Members

  • QObjectCleanupHandler ()
  • ~QObjectCleanupHandler ()
  • QObject * add ( QObject*object )
  • void remove ( QObject*object )
  • bool isEmpty () const
  • void clear ()

Detailed Description

The QObjectCleanupHandler class watches the lifetime of multiple QObjects.

A QObjectCleanupHandler is useful whenever you need to know when a number of QObjects 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 QLibraryInterface
    {
    public:
        ...

        QObject *createObject();

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

    private:
        QObjectCleanupHandler objects;
    };

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

    // QLibraryInterface implementation
    bool FactoryComponent::init()
    {
        return TRUE;
    }

    void FactoryComponent::cleanup()
    {
    }

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

See also Object Model.


Member Function Documentation

QObjectCleanupHandler::QObjectCleanupHandler ()

Constructs an empty QObjectCleanupHandler.

QObjectCleanupHandler::~QObjectCleanupHandler ()

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

QObject* QObjectCleanupHandler::add ( QObject*object )

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

void QObjectCleanupHandler::clear ()

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

bool QObjectCleanupHandler::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 QObjectCleanupHandler::remove ( QObject*object )

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文