Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qobjectcleanuphandler.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
7
40
51
59{
60 if (!object)
61 return nullptr;
62
63 connect(object, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*)));
64 cleanupObjects.insert(0, object);
65 return object;
66}
67
75{
76 int index;
77 if ((index = cleanupObjects.indexOf(object)) != -1) {
78 cleanupObjects.removeAt(index);
79 disconnect(object, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*)));
80 }
81}
82
90{
91 return cleanupObjects.isEmpty();
92}
93
101{
102 while (!cleanupObjects.isEmpty())
103 delete cleanupObjects.takeFirst();
104}
105
106void QObjectCleanupHandler::objectDestroyed(QObject *object)
107{
108 remove(object);
109}
110
112
113#include "moc_qobjectcleanuphandler.cpp"
bool isEmpty() const noexcept
Definition qlist.h:401
void removeAt(qsizetype i)
Definition qlist.h:590
iterator insert(qsizetype i, parameter_type t)
Definition qlist.h:488
value_type takeFirst()
Definition qlist.h:566
bool isEmpty() const
Returns true if this cleanup handler is empty or if all objects in this cleanup handler have been des...
QObject * add(QObject *object)
Adds object to this cleanup handler and returns the pointer to the object.
~QObjectCleanupHandler()
Destroys the cleanup handler.
void clear()
Deletes all objects in this cleanup handler.
void remove(QObject *object)
Removes the object from this cleanup handler.
QObjectCleanupHandler()
Constructs an empty QObjectCleanupHandler.
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
Combined button and popup list for selecting options.
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
GLuint index
[2]
GLuint object
[3]
myObject disconnect()
[26]
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
Definition qlist.h:962