@@ -15,25 +15,31 @@ class StaticPluginInfo : public QPluginFactoryBase::PluginInfo
15
15
16
16
QJsonObject metaData () const override ;
17
17
QObject *instance () override ;
18
+ bool isLoaded () const override ;
19
+ void unload (const QString &key) override ;
18
20
19
21
private:
20
22
QStaticPlugin _plugin;
21
23
};
22
24
25
+ #if QT_CONFIG(library)
26
+
23
27
class DynamicPluginInfo : public QPluginFactoryBase ::PluginInfo
24
28
{
25
29
public:
26
30
DynamicPluginInfo (QScopedPointer<QPluginLoader, QScopedPointerDeleteLater> &loader);
27
31
28
32
QJsonObject metaData () const override ;
29
33
QObject *instance () override ;
30
-
31
- QPluginLoader * loader () const ;
34
+ bool isLoaded () const override ;
35
+ void unload ( const QString &key) override ;
32
36
33
37
private:
34
38
QScopedPointer<QPluginLoader, QScopedPointerDeleteLater> _loader;
35
39
};
36
40
41
+ #endif
42
+
37
43
}
38
44
39
45
@@ -111,6 +117,8 @@ void QPluginFactoryBase::reloadPlugins()
111
117
// find the plugin dir
112
118
auto oldKeys = _plugins.keys ();
113
119
120
+ #if QT_CONFIG(library)
121
+
114
122
QList<QDir> allDirs;
115
123
// first: dirs in path
116
124
// MAJOR remove
@@ -159,6 +167,8 @@ void QPluginFactoryBase::reloadPlugins()
159
167
}
160
168
}
161
169
170
+ #endif
171
+
162
172
// setup static plugins
163
173
for (const auto &info : QPluginLoader::staticPlugins ()) {
164
174
auto keys = checkMeta (info.metaData (), QString ());
@@ -179,30 +189,18 @@ bool QPluginFactoryBase::isLoaded(const QString &key) const
179
189
{
180
190
QMutexLocker _{&_loaderMutex};
181
191
auto info = _plugins.value (key);
182
- if (info) {
183
- auto dynInfo = info.dynamicCast <DynamicPluginInfo>();
184
- if (dynInfo)
185
- return dynInfo->loader ()->isLoaded ();
186
- else // static plugin
187
- return true ;
188
- } else
192
+ if (info)
193
+ return info->isLoaded ();
194
+ else
189
195
return false ;
190
196
}
191
197
192
198
void QPluginFactoryBase::unload (const QString &key)
193
199
{
194
200
QMutexLocker _{&_loaderMutex};
195
201
auto info = _plugins.value (key);
196
- if (info) {
197
- auto dynInfo = info.dynamicCast <DynamicPluginInfo>();
198
- if (dynInfo) {
199
- auto loader = dynInfo->loader ();
200
- if (loader->isLoaded ()){
201
- if (!loader->unload ())
202
- qWarning ().noquote () << " Failed to unload plugin for key" << key << " with error:" << loader->errorString ();
203
- }
204
- }
205
- }
202
+ if (info)
203
+ info->unload (key);
206
204
}
207
205
208
206
QJsonArray QPluginFactoryBase::checkMeta (const QJsonObject &metaData, const QString &filename) const
@@ -228,10 +226,12 @@ QJsonArray QPluginFactoryBase::checkMeta(const QJsonObject &metaData, const QStr
228
226
229
227
230
228
229
+ #if QT_CONFIG(library)
230
+
231
231
QPluginLoadException::QPluginLoadException (QPluginLoader *loader) :
232
- QPluginLoadException {QStringLiteral (" Failed to load plugin \" %1\" with error: %2" )
233
- .arg (loader->fileName (), loader->errorString ())
234
- .toUtf8 ()}
232
+ _what {QStringLiteral (" Failed to load plugin \" %1\" with error: %2" )
233
+ .arg (loader->fileName (), loader->errorString ())
234
+ .toUtf8 ()}
235
235
{}
236
236
237
237
const char *QPluginLoadException::what () const noexcept
@@ -244,14 +244,12 @@ void QPluginLoadException::raise() const
244
244
throw *this ;
245
245
}
246
246
247
- QException *QPluginLoadException::clone () const
247
+ QExceptionBase::Base *QPluginLoadException::clone () const
248
248
{
249
- return new QPluginLoadException (_what) ;
249
+ return new QPluginLoadException{* this } ;
250
250
}
251
251
252
- QPluginLoadException::QPluginLoadException (QByteArray error) :
253
- _what{std::move (error)}
254
- {}
252
+ #endif
255
253
256
254
257
255
@@ -269,6 +267,20 @@ QObject *StaticPluginInfo::instance()
269
267
return _plugin.instance ();
270
268
}
271
269
270
+ bool StaticPluginInfo::isLoaded () const
271
+ {
272
+ return true ;
273
+ }
274
+
275
+ void StaticPluginInfo::unload (const QString &key)
276
+ {
277
+ Q_UNUSED (key)
278
+ }
279
+
280
+
281
+
282
+ #if QT_CONFIG(library)
283
+
272
284
DynamicPluginInfo::DynamicPluginInfo (QScopedPointer<QPluginLoader, QScopedPointerDeleteLater> &loader)
273
285
{
274
286
_loader.swap (loader);
@@ -286,7 +298,17 @@ QObject *DynamicPluginInfo::instance()
286
298
return _loader->instance ();
287
299
}
288
300
289
- QPluginLoader * DynamicPluginInfo::loader () const
301
+ bool DynamicPluginInfo::isLoaded () const
290
302
{
291
- return _loader. data ();
303
+ return _loader-> isLoaded ();
292
304
}
305
+
306
+ void DynamicPluginInfo::unload (const QString &key)
307
+ {
308
+ if (_loader->isLoaded ()){
309
+ if (!_loader->unload ())
310
+ qWarning ().noquote () << " Failed to unload plugin for key" << key << " with error:" << _loader->errorString ();
311
+ }
312
+ }
313
+
314
+ #endif
0 commit comments