Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qfactoryloader_p.h
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// Copyright (C) 2022 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QFACTORYLOADER_P_H
6#define QFACTORYLOADER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "QtCore/qglobal.h"
20#ifndef QT_NO_QOBJECT
21
22#include "QtCore/private/qplugin_p.h"
23#include "QtCore/qcbormap.h"
24#include "QtCore/qcborvalue.h"
25#include "QtCore/qmap.h"
26#include "QtCore/qobject.h"
27#include "QtCore/qplugin.h"
28
29QT_BEGIN_NAMESPACE
30
31class QJsonObject;
32class QLibraryPrivate;
33
35class Q_CORE_EXPORT QFactoryLoader : public QObject
36{
37 Q_OBJECT
38 Q_DECLARE_PRIVATE(QFactoryLoader)
39
40public:
41 explicit QFactoryLoader(const char *iid,
42 const QString &suffix = QString(),
43 Qt::CaseSensitivity = Qt::CaseSensitive);
44
45#if QT_CONFIG(library)
46 ~QFactoryLoader();
47
48 void update();
49 static void refreshAll();
50
51#if defined(Q_OS_UNIX) && !defined (Q_OS_DARWIN)
52 QLibraryPrivate *library(const QString &key) const;
53#endif // Q_OS_UNIX && !Q_OS_DARWIN
54#endif // QT_CONFIG(library)
55
56 void setExtraSearchPath(const QString &path);
57 QMultiMap<int, QString> keyMap() const;
58 int indexOf(const QString &needle) const;
59
60 using MetaDataList = QList<QPluginParsedMetaData>;
61
62 MetaDataList metaData() const;
63 QList<QCborArray> metaDataKeys() const;
64 QObject *instance(int index) const;
65};
66
67template <class PluginInterface, class FactoryInterface, typename ...Args>
68PluginInterface *qLoadPlugin(const QFactoryLoader *loader, const QString &key, Args &&...args)
69{
70 const int index = loader->indexOf(key);
71 if (index != -1) {
72 QObject *factoryObject = loader->instance(index);
73 if (FactoryInterface *factory = qobject_cast<FactoryInterface *>(factoryObject))
74 if (PluginInterface *result = factory->create(key, std::forward<Args>(args)...))
75 return result;
76 }
77 return nullptr;
78}
79
80template <class PluginInterface, class FactoryInterface, typename Arg>
81Q_DECL_DEPRECATED PluginInterface *qLoadPlugin1(const QFactoryLoader *loader, const QString &key, Arg &&arg)
82{ return qLoadPlugin<PluginInterface, FactoryInterface>(loader, key, std::forward<Arg>(arg)); }
83
84QT_END_NAMESPACE
85
86#endif // QT_NO_QOBJECT
87
88#endif // QFACTORYLOADER_P_H
bool parse(QByteArrayView input)
QJsonObject toJson() const
Q_TRACE_POINT(qtcore, QFactoryLoader_update, const QString &fileName)
static bool isIidMatch(QByteArrayView raw, QLatin1StringView iid)
static IterationResult iterateInPluginMetaData(QByteArrayView raw, F &&f)
PluginInterface * qLoadPlugin(const QFactoryLoader *loader, const QString &key, Args &&...args)
QtPluginMetaDataKeys
Definition qplugin_p.h:26
#define QT_PLUGIN_FOREACH_METADATA(F)
Definition qplugin_p.h:38