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
4#ifndef QLIBRARY_H
5#define QLIBRARY_H
6
7#include <QtCore/qobject.h>
8#include <QtCore/qtaggedpointer.h>
9
10QT_REQUIRE_CONFIG(library);
11
12QT_BEGIN_NAMESPACE
13
14class QLibraryPrivate;
15
16class Q_CORE_EXPORT QLibrary : public QObject
17{
18 Q_OBJECT
19 Q_PROPERTY(QString fileName READ fileName WRITE setFileName)
20 Q_PROPERTY(LoadHints loadHints READ loadHints WRITE setLoadHints)
21public:
22 enum LoadHint {
23 ResolveAllSymbolsHint = 0x01,
24 ExportExternalSymbolsHint = 0x02,
25 LoadArchiveMemberHint = 0x04,
26 PreventUnloadHint = 0x08,
27 DeepBindHint = 0x10
28 };
29 Q_DECLARE_FLAGS(LoadHints, LoadHint)
30 Q_ENUM(LoadHint)
31 Q_FLAG(LoadHints)
32
33 explicit QLibrary(QObject *parent = nullptr);
34 explicit QLibrary(const QString &fileName, QObject *parent = nullptr);
35 explicit QLibrary(const QString &fileName, int verNum, QObject *parent = nullptr);
36 explicit QLibrary(const QString &fileName, const QString &version, QObject *parent = nullptr);
37 ~QLibrary();
38
39 QFunctionPointer resolve(const char *symbol);
40 static QFunctionPointer resolve(const QString &fileName, const char *symbol);
41 static QFunctionPointer resolve(const QString &fileName, int verNum, const char *symbol);
42 static QFunctionPointer resolve(const QString &fileName, const QString &version, const char *symbol);
43
44 bool load();
45 bool unload();
46 bool isLoaded() const;
47
48 static bool isLibrary(const QString &fileName);
49
50 void setFileName(const QString &fileName);
51 QString fileName() const;
52
53 void setFileNameAndVersion(const QString &fileName, int verNum);
54 void setFileNameAndVersion(const QString &fileName, const QString &version);
55 QString errorString() const;
56
57 void setLoadHints(LoadHints hints);
58 LoadHints loadHints() const;
59
60private:
61 enum LoadStatusTag {
62 NotLoaded,
63 Loaded
64 };
65
66 QTaggedPointer<QLibraryPrivate, LoadStatusTag> d = nullptr;
67 Q_DISABLE_COPY(QLibrary)
68};
69
70Q_DECLARE_OPERATORS_FOR_FLAGS(QLibrary::LoadHints)
71
72QT_END_NAMESPACE
73
74#endif //QLIBRARY_H
75

source code of qtbase/src/corelib/plugin/qlibrary.h