QtCanpool 3.3.0
载入中...
搜索中...
未找到
qxobjectpool.h
浏览该文件的文档.
1
5#ifndef QXOBJECTPOOL_H
6#define QXOBJECTPOOL_H
7
8#include "qxplugin_global.h"
9
10#include <QtCore/QList>
11#include <QtCore/QObject>
12#include <QtCore/QPointer>
13#include <QtCore/QString>
14
16
49class QX_PLUGIN_EXPORT QxObjectPool : public QObject
50{
51 Q_OBJECT
52public:
53 explicit QxObjectPool(QObject *parent = Q_NULLPTR);
54 ~QxObjectPool() override;
55
60 void addObject(QObject *object);
62 void removeObject(QObject *object);
63
65 QList<QObject *> objects() const;
67 QObject *objectByName(const QString &name) const;
68
77 template <typename T> T *object() const
78 {
79 const QList<QObject *> all = objects();
80 for (QObject *candidate : all) {
81 if (T *match = qobject_cast<T *>(candidate))
82 return match;
83 }
84 return Q_NULLPTR;
85 }
86
87Q_SIGNALS:
89 void objectAdded(QObject *object);
98 void aboutToRemoveObject(QObject *object);
99private:
100 Q_DISABLE_COPY(QxObjectPool)
101 QList<QPointer<QObject>> m_objects;
102};
103
105
106#endif // QXOBJECTPOOL_H
The meeting point for two plugins that want to cooperate.
void aboutToRemoveObject(QObject *object)
Emitted just before removeObject() takes object out.
T * object() const
The first live published object castable to T, or null.
void objectAdded(QObject *object)
Emitted after object joined the pool.
#define Q_NULLPTR
Copyleft (C) 2025 maminjie canpool@163.com SPDX-License-Identifier: MulanPSL-2.0
#define QX_PLUGIN_BEGIN_NAMESPACE
#define QX_PLUGIN_END_NAMESPACE
#define QX_PLUGIN_EXPORT
const char * name
Definition qxtheme.cpp:25