Qt 4.8
Public Functions | Static Public Functions | List of all members
QFactoryLoader Class Reference

#include <qfactoryloader_p.h>

Inheritance diagram for QFactoryLoader:
QObject

Public Functions

QObjectinstance (const QString &key) const
 
QStringList keys () const
 
QLibraryPrivatelibrary (const QString &key) const
 
 QFactoryLoader (const char *iid, const QString &suffix=QString(), Qt::CaseSensitivity=Qt::CaseSensitive)
 
void update ()
 
void updateDir (const QString &pluginDir, QSettings &settings)
 
 ~QFactoryLoader ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Functions

static void refreshAll ()
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 66 of file qfactoryloader_p.h.

Constructors and Destructors

◆ QFactoryLoader()

QFactoryLoader::QFactoryLoader ( const char *  iid,
const QString suffix = QString(),
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)

Definition at line 108 of file qfactoryloader.cpp.

112 {
115  d->iid = iid;
116  d->cs = cs;
117  d->suffix = suffix;
118 
119 
120  QMutexLocker locker(qt_factoryloader_mutex());
121  update();
122  qt_factory_loaders()->append(this);
123 #ifdef Q_OS_SYMBIAN
124  // kick off Symbian plugin watcher for updates
125  qt_symbian_system_plugin_watcher();
126 #endif
127 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition: qobject.cpp:1458
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QThread * mainThread()
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QByteArray suffix

◆ ~QFactoryLoader()

QFactoryLoader::~QFactoryLoader ( )

Definition at line 244 of file qfactoryloader.cpp.

245 {
246  QMutexLocker locker(qt_factoryloader_mutex());
247  qt_factory_loaders()->removeAll(this);
248 }
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

Functions

◆ instance()

QObject * QFactoryLoader::instance ( const QString key) const

Definition at line 263 of file qfactoryloader.cpp.

Referenced by QAudioDeviceFactory::availableDevices(), createForName(), createReadHandlerHelper(), if(), Q_GLOBAL_STATIC_WITH_ARGS(), qt_guiPlatformMenuBarFactory(), qt_guiPlatformPlugin(), QImageWriter::supportedImageFormats(), QImageReader::supportedImageFormats(), QNetworkConfigurationManagerPrivate::updateConfigurations(), and updateDir().

264 {
265  Q_D(const QFactoryLoader);
266  QMutexLocker locker(&d->mutex);
268  for (int i = 0; i < instances.count(); ++i)
269  if (QFactoryInterface *factory = qobject_cast<QFactoryInterface*>(instances.at(i)))
270  if (instances.at(i)->qt_metacast(d->iid) && factory->keys().contains(key, Qt::CaseInsensitive))
271  return instances.at(i);
272 
273  QString lowered = d->cs ? key : key.toLower();
274  if (QLibraryPrivate* library = d->keyMap.value(lowered)) {
275  if (library->instance || library->loadPlugin()) {
276  if (QObject *obj = library->instance()) {
277  if (obj && !obj->parent())
278  obj->moveToThread(QCoreApplicationPrivate::mainThread());
279  return obj;
280  }
281  }
282  }
283  return 0;
284 }
double d
Definition: qnumeric_p.h:62
QtPluginInstanceFunction instance
Definition: qlibrary_p.h:95
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
static QObjectList staticInstances()
Returns a list of static plugin instances (root components) held by the plugin loader.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
static QThread * mainThread()
int key
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
bool loadPlugin()
Definition: qlibrary.cpp:517
QLibraryPrivate * library(const QString &key) const

◆ keys()

QStringList QFactoryLoader::keys ( ) const

Definition at line 250 of file qfactoryloader.cpp.

Referenced by QTextCodec::availableCodecs(), QAudioDeviceFactory::availableDevices(), QTextCodec::availableMibs(), createForName(), createReadHandlerHelper(), QIconLoader::ensureInitialized(), Q_GLOBAL_STATIC_WITH_ARGS(), QImageWriter::supportedImageFormats(), QImageReader::supportedImageFormats(), QNetworkConfigurationManagerPrivate::updateConfigurations(), and updateDir().

251 {
252  Q_D(const QFactoryLoader);
253  QMutexLocker locker(&d->mutex);
254  QStringList keys = d->keyList;
256  for (int i = 0; i < instances.count(); ++i)
257  if (QFactoryInterface *factory = qobject_cast<QFactoryInterface*>(instances.at(i)))
258  if (instances.at(i)->qt_metacast(d->iid))
259  keys += factory->keys();
260  return keys;
261 }
double d
Definition: qnumeric_p.h:62
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_D(Class)
Definition: qglobal.h:2482
static QObjectList staticInstances()
Returns a list of static plugin instances (root components) held by the plugin loader.
QStringList keys() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ library()

QLibraryPrivate * QFactoryLoader::library ( const QString key) const

Definition at line 287 of file qfactoryloader.cpp.

Referenced by instance(), and updateDir().

288 {
289  Q_D(const QFactoryLoader);
290  return d->keyMap.value(d->cs ? key : key.toLower());
291 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389

◆ refreshAll()

void QFactoryLoader::refreshAll ( )
static

Definition at line 294 of file qfactoryloader.cpp.

Referenced by QCoreApplication::addLibraryPath(), QCoreApplication::QCoreApplication(), QCoreApplication::removeLibraryPath(), and QCoreApplication::setLibraryPaths().

295 {
296  QMutexLocker locker(qt_factoryloader_mutex());
297  QList<QFactoryLoader *> *loaders = qt_factory_loaders();
299  it != loaders->constEnd(); ++it) {
300  (*it)->update();
301  }
302 }
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
The QList::const_iterator class provides an STL-style const iterator for QList and QQueue...
Definition: qlist.h:228
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ update()

void QFactoryLoader::update ( )

Definition at line 221 of file qfactoryloader.cpp.

Referenced by QFactoryLoader(), and QWidget::setContentsMargins().

222 {
223 #ifdef QT_SHARED
226  QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
227  for (int i = 0; i < paths.count(); ++i) {
228  const QString &pluginDir = paths.at(i);
229  // Already loaded, skip it...
230  if (d->loadedPaths.contains(pluginDir))
231  continue;
232  d->loadedPaths << pluginDir;
233  updateDir(pluginDir, settings);
234  }
235 #else
237  if (qt_debug_component()) {
238  qDebug() << "QFactoryLoader::QFactoryLoader() ignoring" << d->iid
239  << "since plugins are disabled in static builds";
240  }
241 #endif
242 }
double d
Definition: qnumeric_p.h:62
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void updateDir(const QString &pluginDir, QSettings &settings)
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QStringList libraryPaths()
Returns a list of paths that the application will search when dynamically loading libraries...
bool qt_debug_component()
Definition: qlibrary.cpp:1319

◆ updateDir()

void QFactoryLoader::updateDir ( const QString pluginDir,
QSettings settings 
)

Definition at line 130 of file qfactoryloader.cpp.

Referenced by update().

131 {
133  QString path = pluginDir + d->suffix;
134  if (!QDir(path).exists(QLatin1String(".")))
135  return;
136 
137  QStringList plugins = QDir(path).entryList(QDir::Files);
139  for (int j = 0; j < plugins.count(); ++j) {
140  QString fileName = QDir::cleanPath(path + QLatin1Char('/') + plugins.at(j));
141 
142  if (qt_debug_component()) {
143  qDebug() << "QFactoryLoader::QFactoryLoader() looking at" << fileName;
144  }
145  library = QLibraryPrivate::findOrCreate(QFileInfo(fileName).canonicalFilePath());
146  if (!library->isPlugin(&settings)) {
147  if (qt_debug_component()) {
148  qDebug() << library->errorString;
149  qDebug() << " not a plugin";
150  }
151  library->release();
152  continue;
153  }
154  QString regkey = QString::fromLatin1("Qt Factory Cache %1.%2/%3:/%4")
155  .arg((QT_VERSION & 0xff0000) >> 16)
156  .arg((QT_VERSION & 0xff00) >> 8)
157  .arg(QLatin1String(d->iid))
158  .arg(fileName);
159  QStringList reg, keys;
160  reg = settings.value(regkey).toStringList();
161  if (reg.count() && library->lastModified == reg[0]) {
162  keys = reg;
163  keys.removeFirst();
164  } else {
165  if (!library->loadPlugin()) {
166  if (qt_debug_component()) {
167  qDebug() << library->errorString;
168  qDebug() << " could not load";
169  }
170  library->release();
171  continue;
172  }
173  QObject *instance = library->instance();
174  if (!instance) {
175  library->release();
176  // ignore plugins that have a valid signature but cannot be loaded.
177  continue;
178  }
180  if (instance && factory && instance->qt_metacast(d->iid))
181  keys = factory->keys();
182  if (keys.isEmpty())
183  library->unload();
184  reg.clear();
185  reg << library->lastModified;
186  reg += keys;
187  settings.setValue(regkey, reg);
188  }
189  if (qt_debug_component()) {
190  qDebug() << "keys" << keys;
191  }
192 
193  if (keys.isEmpty()) {
194  library->release();
195  continue;
196  }
197 
198  int keysUsed = 0;
199  for (int k = 0; k < keys.count(); ++k) {
200  // first come first serve, unless the first
201  // library was built with a future Qt version,
202  // whereas the new one has a Qt version that fits
203  // better
204  QString key = keys.at(k);
205  if (!d->cs)
206  key = key.toLower();
207  QLibraryPrivate *previous = d->keyMap.value(key);
208  if (!previous || (previous->qt_version > QT_VERSION && library->qt_version <= QT_VERSION)) {
209  d->keyMap[key] = library;
210  d->keyList += keys.at(k);
211  keysUsed++;
212  }
213  }
214  if (keysUsed)
215  d->libraryList += library;
216  else
217  library->release();
218  }
219 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
bool isPlugin(QSettings *settings=0)
Definition: qlibrary.cpp:669
void setValue(const QString &key, const QVariant &value)
Sets the value of setting key to value.
Definition: qsettings.cpp:3328
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
Definition: qsettings.cpp:3460
static QLibraryPrivate * findOrCreate(const QString &fileName, const QString &version=QString())
Definition: qlibrary.cpp:438
QtPluginInstanceFunction instance
Definition: qlibrary_p.h:95
QString lastModified
Definition: qlibrary_p.h:97
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
Q_CORE_EXPORT void qDebug(const char *,...)
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
Definition: qvariant.cpp:2259
QStringList keys() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
void removeFirst()
Removes the first item in the list.
Definition: qlist.h:286
void clear()
Removes all items from the list.
Definition: qlist.h:764
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QString errorString
Definition: qlibrary_p.h:99
virtual QStringList keys() const =0
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QObject * instance(const QString &key) const
int key
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
bool loadPlugin()
Definition: qlibrary.cpp:517
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
QLibraryPrivate * library(const QString &key) const
static QString fileName(const QString &fileUrl)
QStringList entryList(Filters filters=NoFilter, SortFlags sort=NoSort) const
Returns a list of the names of all the files and directories in the directory, ordered according to t...
Definition: qdir.cpp:1290
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool qt_debug_component()
Definition: qlibrary.cpp:1319
#define QT_VERSION
This macro expands a numeric value of the form 0xMMNNPP (MM = major, NN = minor, PP = patch) that spe...
Definition: qglobal.h:51

The documentation for this class was generated from the following files: