Qt 4.8
qplugin.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QPLUGIN_H
43 #define QPLUGIN_H
44 
45 #include <QtCore/qobject.h>
46 #include <QtCore/qpointer.h>
47 
49 
51 
52 QT_MODULE(Core)
53 
54 #ifndef Q_EXTERN_C
55 # ifdef __cplusplus
56 # define Q_EXTERN_C extern "C"
57 # else
58 # define Q_EXTERN_C extern
59 # endif
60 #endif
61 
62 typedef QObject *(*QtPluginInstanceFunction)();
63 
65 
66 #define Q_IMPORT_PLUGIN(PLUGIN) \
67  extern QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance_##PLUGIN(); \
68  class Static##PLUGIN##PluginInstance{ \
69  public: \
70  Static##PLUGIN##PluginInstance() { \
71  qRegisterStaticPluginInstanceFunction(qt_plugin_instance_##PLUGIN); \
72  } \
73  }; \
74  static Static##PLUGIN##PluginInstance static##PLUGIN##Instance;
75 
76 #define Q_PLUGIN_INSTANCE(IMPLEMENTATION) \
77  { \
78  static QT_PREPEND_NAMESPACE(QPointer)<QT_PREPEND_NAMESPACE(QObject)> _instance; \
79  if (!_instance) \
80  _instance = new IMPLEMENTATION; \
81  return _instance; \
82  }
83 
84 # define Q_EXPORT_PLUGIN(PLUGIN) \
85  Q_EXPORT_PLUGIN2(PLUGIN, PLUGIN)
86 
87 # define Q_EXPORT_STATIC_PLUGIN(PLUGIN) \
88  Q_EXPORT_STATIC_PLUGIN2(PLUGIN, PLUGIN)
89 
90 #if defined(QT_STATICPLUGIN)
91 
92 # define Q_EXPORT_PLUGIN2(PLUGIN, PLUGINCLASS) \
93  QT_PREPEND_NAMESPACE(QObject) \
94  *qt_plugin_instance_##PLUGIN() \
95  Q_PLUGIN_INSTANCE(PLUGINCLASS)
96 
97 # define Q_EXPORT_STATIC_PLUGIN2(PLUGIN, PLUGINCLASS) \
98  Q_EXPORT_PLUGIN2(PLUGIN, PLUGINCLASS)
99 
100 #else
101 // NOTE: if you change pattern, you MUST change the pattern in
102 // qlibrary.cpp as well. changing the pattern will break all
103 // backwards compatibility as well (no old plugins will be loaded).
104 // QT5: should probably remove the entire pattern thing and do the section
105 // trick for all platforms. for now, keep it and fallback to scan for it.
106 # ifdef QPLUGIN_DEBUG_STR
107 # undef QPLUGIN_DEBUG_STR
108 # endif
109 # ifdef QT_NO_DEBUG
110 # define QPLUGIN_DEBUG_STR "false"
111 # define QPLUGIN_SECTION_DEBUG_STR ""
112 # else
113 # define QPLUGIN_DEBUG_STR "true"
114 # define QPLUGIN_SECTION_DEBUG_STR ".debug"
115 # endif
116 # define Q_PLUGIN_VERIFICATION_DATA \
117  static const char qt_plugin_verification_data[] = \
118  "pattern=QT_PLUGIN_VERIFICATION_DATA\n" \
119  "version=" QT_VERSION_STR "\n" \
120  "debug=" QPLUGIN_DEBUG_STR "\n" \
121  "buildkey=" QT_BUILD_KEY;
122 
123 # if defined (Q_OF_ELF) && defined (Q_CC_GNU)
124 # define Q_PLUGIN_VERIFICATION_SECTION \
125  __attribute__ ((section (".qtplugin"))) __attribute__((used))
126 # else
127 # define Q_PLUGIN_VERIFICATION_SECTION
128 # endif
129 
130 # if defined (Q_OS_WIN32) && defined(Q_CC_BOR)
131 # define Q_STANDARD_CALL __stdcall
132 # else
133 # define Q_STANDARD_CALL
134 # endif
135 
136 # define Q_EXPORT_PLUGIN2(PLUGIN, PLUGINCLASS) \
137  Q_PLUGIN_VERIFICATION_SECTION Q_PLUGIN_VERIFICATION_DATA \
138  Q_EXTERN_C Q_DECL_EXPORT \
139  const char * Q_STANDARD_CALL qt_plugin_query_verification_data() \
140  { return qt_plugin_verification_data; } \
141  Q_EXTERN_C Q_DECL_EXPORT QT_PREPEND_NAMESPACE(QObject) * Q_STANDARD_CALL qt_plugin_instance() \
142  Q_PLUGIN_INSTANCE(PLUGINCLASS)
143 
144 # define Q_EXPORT_STATIC_PLUGIN2(PLUGIN, PLUGINCLASS)
145 
146 #endif
147 
149 
151 
152 #endif // Q_PLUGIN_H
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
void Q_CORE_EXPORT qRegisterStaticPluginInstanceFunction(QtPluginInstanceFunction function)
Registers the given function with the plugin loader.
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QObject *(* QtPluginInstanceFunction)()
Definition: qplugin.h:62
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
#define QT_END_HEADER
Definition: qglobal.h:137