Carousel
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Pages
Public Member Functions | Protected Attributes | List of all members
ComponentLoader Class Reference

The default implementation of the IComponentLoader class. More...

#include <ComponentLoader.h>

Inherits QObject, and IComponentLoader.

Public Member Functions

 ComponentLoader (QObject *parent=nullptr)
 
 ComponentLoader (const QString &fileName, QObject *parent=nullptr)
 
 ~ComponentLoader ()
 
bool deleteInstance ()
 
QString errorString () const
 
QString fileName () const
 
IComponentinstance ()
 
bool isLoaded () const
 
bool load ()
 
QLibrary::LoadHints loadHints () const
 
void setFileName (const QString &fileName)
 
void setLoadHints (QLibrary::LoadHints loadHints)
 
bool unload ()
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
bool blockSignals (bool block)
 
QObjectchild (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArraydynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObjectparent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThreadthread () const
 
- Public Member Functions inherited from IComponentLoader
virtual ~IComponentLoader ()
 

Protected Attributes

IComponentm_instance
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObjectsender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

The default implementation of the IComponentLoader class.

It is very similiar with QPluginLoader, but with few differences: ComponentLoader returns IComponent instead of QObject; ComponentLoader can be used with if your application is statically linked against Qt; ComponentLoader takes ownership for the loaded component instance; Load hints are set to QLibrary::ResolveAllSymbolsHint and QLibrary::ExportExternalSymbolsHinthints by default to enable RTTI cross the library bounds (used in IServiceLocator).

ComponentLoader provides access to a IComponent, stored in a shared library (a DLL) and offers these benefits over shared libraries accessed using QLibrary.

ComponentLoader provides direct access to a component object (instance()), instead of forcing you to resolve a C function manually.

An instance of a ComponentLoader object operates on a single shared library file, which we call a component. It provides access to the functionality in the component in a platform-independent way. To specify which component to load, either pass a file name in the constructor or set it with setFileName().

The most important functions are load() to dynamically load the component file, isLoaded() to check whether loading was successful, and instance() to access the root in the component. The instance() function implicitly tries to load the component if it has not been loaded yet.

Note
: ComponentLoader takes ownership for the loaded component instance, and it will be until ComponentLoader has been destroyed or deleteInstance() is called.

Constructor & Destructor Documentation

ComponentLoader::~ComponentLoader ( )

Destroys the ComponentLoader object.

unload() will be called explicitly, the component will be destroyed (if any).

Member Function Documentation

QString ComponentLoader::errorString ( ) const
virtual

Returns a text string with the description of the last error that occurred.

Implements IComponentLoader.

bool ComponentLoader::deleteInstance ( )
virtual

Deletes the component and returns true if the component was deleted; otherwise returns false.

This happens automatically on ComponentLoader destructor, so you shouldn't normally need to call this function.

If other instances of ComponentLoader are using the same component, the call will fail, and unloading will only happen when every instance has called unload().

Don't try to delete the component object. Instead rely on that deleteInstance() will automatically delete it.

See Also
instance().

Implements IComponentLoader.

QString ComponentLoader::fileName ( ) const
virtual

Returns the file name of the component.

By default, this property contains an empty string.

Implements IComponentLoader.

IComponent* ComponentLoader::instance ( )
virtual

Returns the root object of the component. The component is loaded if necessary. The function returns nullptr if the component could not be loaded or if the component could not be instantiated.

If the component object was destroyed (unload()), calling this function creates a new instance.

The root component, returned by this function, is deleted when the IComponentLoader is destroyed. If you want to manage component lifetime your-self, you should call unload().

See Also
load().

Implements IComponentLoader.

bool ComponentLoader::isLoaded ( ) const
virtual

Returns true if the component is loaded; otherwise returns false.

Implements IComponentLoader.

bool ComponentLoader::load ( )
virtual

Loads the component and returns true if the component was loaded successfully; otherwise returns false. Since instance() always calls this function before resolving any symbols it is not necessary to call it explicitly. In some situations you might want the component loaded in advance, in which case you would use this function.

See Also
deleteInstance().

Implements IComponentLoader.

QLibrary::LoadHints ComponentLoader::loadHints ( ) const
virtual

Gets the give the load() function some hints on how it should behave. By default, QLibrary::ResolveAllSymbolsHint and QLibrary::ExportExternalSymbolsHinthints are set to enable RTTI cross the library bounds.

See the documentation of QLibrary::loadHints() for a complete description of how this property works.

Implements IComponentLoader.

void ComponentLoader::setFileName ( const QString fileName)
virtual

Sets the file name of loaded component library.

To be loadable, the file's suffix must be a valid suffix for a loadable library in accordance with the platform, e.g. .so on Unix, .dylib on Mac OS X, and .dll on Windows. The suffix can be verified with QLibrary::isLibrary().

If the file name does not exist, it will not be set. This property will then contain an empty string.

See Also
fileName().

Implements IComponentLoader.

void ComponentLoader::setLoadHints ( QLibrary::LoadHints  loadHints)
virtual

Sets the file name of loaded component library.

See Also
loadHints().

Implements IComponentLoader.

bool ComponentLoader::unload ( )
virtual

Unloads the component and returns true if the component could be unloaded; otherwise returns false.

This happens automatically on IComponentLoader destructor, so you shouldn't normally need to call this function.

If other instances of IComponentLoader are using the same component, the call will fail, and unloading will only happen when every instance has called unload().

Don't try to delete the component object. Instead rely on that unload() will automatically delete it when needed.

See Also
instance(), deleteInstance() and load().

Implements IComponentLoader.