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
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
30
31class QJsonObject;
32class QLibraryPrivate;
33
35{
37 bool setError(const QString &errorString) Q_DECL_COLD_FUNCTION
38 {
40 return false;
41 }
42public:
45
46 bool isError() const { return !data.isMap(); }
47 QString errorString() const { return data.toString(); }
48
50 bool parse(QPluginMetaData metaData)
51 { return parse(QByteArrayView(reinterpret_cast<const char *>(metaData.data), metaData.size)); }
52
53 QJsonObject toJson() const; // only for QLibrary & QPluginLoader
54
55 // if data is not a map, toMap() returns empty, so shall these functions
56 QCborMap toCbor() const { return data.toMap(); }
57 QCborValue value(QtPluginMetaDataKeys k) const { return data[int(k)]; }
58};
59
61class Q_CORE_EXPORT QFactoryLoader : public QObject
62{
64 Q_DECLARE_PRIVATE(QFactoryLoader)
65
66public:
67 explicit QFactoryLoader(const char *iid,
68 const QString &suffix = QString(),
70
71#if QT_CONFIG(library)
73
74 void update();
75 static void refreshAll();
76
77#if defined(Q_OS_UNIX) && !defined (Q_OS_DARWIN)
78 QLibraryPrivate *library(const QString &key) const;
79#endif // Q_OS_UNIX && !Q_OS_DARWIN
80#endif // QT_CONFIG(library)
81
82 void setExtraSearchPath(const QString &path);
83 QMultiMap<int, QString> keyMap() const;
84 int indexOf(const QString &needle) const;
85
86 using MetaDataList = QList<QPluginParsedMetaData>;
87
88 MetaDataList metaData() const;
89 QList<QCborArray> metaDataKeys() const;
90 QObject *instance(int index) const;
91};
92
93template <class PluginInterface, class FactoryInterface, typename ...Args>
94PluginInterface *qLoadPlugin(const QFactoryLoader *loader, const QString &key, Args &&...args)
95{
96 const int index = loader->indexOf(key);
97 if (index != -1) {
98 QObject *factoryObject = loader->instance(index);
99 if (FactoryInterface *factory = qobject_cast<FactoryInterface *>(factoryObject))
100 if (PluginInterface *result = factory->create(key, std::forward<Args>(args)...))
101 return result;
102 }
103 return nullptr;
104}
105
106template <class PluginInterface, class FactoryInterface, typename Arg>
107Q_DECL_DEPRECATED PluginInterface *qLoadPlugin1(const QFactoryLoader *loader, const QString &key, Arg &&arg)
108{ return qLoadPlugin<PluginInterface, FactoryInterface>(loader, key, std::forward<Arg>(arg)); }
109
111
112#endif // QT_NO_QOBJECT
113
114#endif // QFACTORYLOADER_P_H
\inmodule QtCore\reentrant
Definition qcbormap.h:21
\inmodule QtCore\reentrant
Definition qcborvalue.h:47
int indexOf(const QString &needle) const
QList< QPluginParsedMetaData > MetaDataList
QObject * instance(int index) const
\inmodule QtCore\reentrant
Definition qjsonobject.h:20
\inmodule QtCore
Definition qobject.h:103
QPluginParsedMetaData(QByteArrayView input)
QCborValue value(QtPluginMetaDataKeys k) const
bool parse(QByteArrayView input)
QCborMap toCbor() const
bool parse(QPluginMetaData metaData)
QJsonObject toJson() const
QPluginParsedMetaData()=default
QString errorString() const
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
CaseSensitivity
@ CaseSensitive
#define Q_DECL_DEPRECATED
#define Q_DECL_COLD_FUNCTION
PluginInterface * qLoadPlugin(const QFactoryLoader *loader, const QString &key, Args &&...args)
Q_DECL_DEPRECATED PluginInterface * qLoadPlugin1(const QFactoryLoader *loader, const QString &key, Arg &&arg)
GLuint64 key
GLuint index
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei const GLchar *const * path
GLuint64EXT * result
[6]
GLenum GLenum GLenum input
QtPluginMetaDataKeys
Definition qplugin_p.h:22
SSL_CTX int void * arg
#define Q_OBJECT
static const struct @450 keyMap[]
list indexOf("B")
QItemEditorFactory * factory
QJSValueList args
const void * data
Definition qplugin.h:103