Qt 4.8
Public Types | Public Functions | Static Public Functions | Properties | List of all members
QLibrary Class Reference

The QLibrary class loads shared libraries at runtime. More...

#include <qlibrary.h>

Inheritance diagram for QLibrary:
QObject

Public Types

enum  LoadHint { ResolveAllSymbolsHint = 0x01, ExportExternalSymbolsHint = 0x02, LoadArchiveMemberHint = 0x04, ImprovedSearchHeuristics = 0x08 }
 This enum describes the possible hints that can be used to change the way libraries are handled when they are loaded. More...
 

Public Functions

QString errorString () const
 Returns a text string with the description of the last error that occurred. More...
 
QString fileName () const
 
bool isLoaded () const
 Returns true if the library is loaded; otherwise returns false. More...
 
bool load ()
 Loads the library and returns true if the library was loaded successfully; otherwise returns false. More...
 
LoadHints loadHints () const
 
 QLibrary (QObject *parent=0)
 Constructs a library with the given parent. More...
 
 QLibrary (const QString &fileName, QObject *parent=0)
 Constructs a library object with the given parent that will load the library specified by fileName. More...
 
 QLibrary (const QString &fileName, int verNum, QObject *parent=0)
 Constructs a library object with the given parent that will load the library specified by fileName and major version number verNum. More...
 
 QLibrary (const QString &fileName, const QString &version, QObject *parent=0)
 Constructs a library object with the given parent that will load the library specified by fileName and full version number version. More...
 
void * resolve (const char *symbol)
 Returns the address of the exported symbol symbol. More...
 
void setFileName (const QString &fileName)
 
void setFileNameAndVersion (const QString &fileName, int verNum)
 Sets the fileName property and major version number to fileName and versionNumber respectively. More...
 
void setFileNameAndVersion (const QString &fileName, const QString &version)
 Sets the fileName property and full version number to fileName and version respectively. More...
 
void setLoadHints (LoadHints hints)
 
bool unload ()
 Unloads the library and returns true if the library could be unloaded; otherwise returns false. More...
 
 ~QLibrary ()
 Destroys the QLibrary object. More...
 
- 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 bool isLibrary (const QString &fileName)
 Returns true if fileName has a valid suffix for a loadable library; otherwise returns false. More...
 
static void * resolve (const QString &fileName, const char *symbol)
 Loads the library fileName and returns the address of the exported symbol symbol. More...
 
static void * resolve (const QString &fileName, int verNum, const char *symbol)
 Loads the library fileName with major version number verNum and returns the address of the exported symbol symbol. More...
 
static void * resolve (const QString &fileName, const QString &version, const char *symbol)
 Loads the library fileName with full version number version and returns the address of the exported symbol symbol. More...
 
- 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)
 

Properties

QLibraryPrivated
 
bool did_load
 
QString fileName
 the file name of the library More...
 
LoadHints loadHints
 Give the load() function some hints on how it should behave. More...
 

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

The QLibrary class loads shared libraries at runtime.

Note
This class or function is reentrant.

An instance of a QLibrary object operates on a single shared object file (which we call a "library", but is also known as a "DLL"). A QLibrary provides access to the functionality in the library in a platform independent way. You can either pass a file name in the constructor, or set it explicitly with setFileName(). When loading the library, QLibrary searches in all the system-specific library locations (e.g. LD_LIBRARY_PATH on Unix), unless the file name has an absolute path. If the file cannot be found, QLibrary tries the name with different platform-specific file suffixes, like ".so" on Unix, ".dylib" on the Mac, or ".dll" on Windows and Symbian. This makes it possible to specify shared libraries that are only identified by their basename (i.e. without their suffix), so the same code will work on different operating systems.

The most important functions are load() to dynamically load the library file, isLoaded() to check whether loading was successful, and resolve() to resolve a symbol in the library. The resolve() function implicitly tries to load the library if it has not been loaded yet. Multiple instances of QLibrary can be used to access the same physical library. Once loaded, libraries remain in memory until the application terminates. You can attempt to unload a library using unload(), but if other instances of QLibrary are using the same library, the call will fail, and unloading will only happen when every instance has called unload().

A typical use of QLibrary is to resolve an exported symbol in a library, and to call the C function that this symbol represents. This is called "explicit linking" in contrast to "implicit linking", which is done by the link step in the build process when linking an executable against a library.

Note: In Symbian resolving symbols using their names is supported only if the library is built as STDDLL. Otherwise ordinals must be used. Also, in Symbian the path of the library is ignored and system default library location is always used.

The following code snippet loads a library, resolves the symbol "mysymbol", and calls the function if everything succeeded. If something goes wrong, e.g. the library file does not exist or the symbol is not defined, the function pointer will be 0 and won't be called.

QLibrary myLib("mylib");
typedef void (*MyPrototype)();
MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol");
if (myFunction)
myFunction();

The symbol must be exported as a C function from the library for resolve() to work. This means that the function must be wrapped in an extern "C" block if the library is compiled with a C++ compiler. On Windows, this also requires the use of a dllexport macro; see resolve() for the details of how this is done. For convenience, there is a static resolve() function which you can use if you just want to call a function in a library without explicitly loading the library first:

typedef void (*MyPrototype)();
MyPrototype myFunction =
(MyPrototype) QLibrary::resolve("mylib", "mysymbol");
if (myFunction)
myFunction();
See also
QPluginLoader

Definition at line 62 of file qlibrary.h.

Enumerations

◆ LoadHint

This enum describes the possible hints that can be used to change the way libraries are handled when they are loaded.

These values indicate how symbols are resolved when libraries are loaded, and are specified using the setLoadHints() function.

  • ResolveAllSymbolsHint Causes all symbols in a library to be resolved when it is loaded, not simply when resolve() is called.
  • ExportExternalSymbolsHint Exports unresolved and external symbols in the library so that they can be resolved in other dynamically-loaded libraries loaded later.
  • LoadArchiveMemberHint Allows the file name of the library to specify a particular object file within an archive file. If this hint is given, the filename of the library consists of a path, which is a reference to an archive file, followed by a reference to the archive member.
See also
loadHints
Enumerator
ResolveAllSymbolsHint 
ExportExternalSymbolsHint 
LoadArchiveMemberHint 
ImprovedSearchHeuristics 

Definition at line 69 of file qlibrary.h.

Constructors and Destructors

◆ QLibrary() [1/4]

QLibrary::QLibrary ( QObject parent = 0)
explicit

Constructs a library with the given parent.

Definition at line 957 of file qlibrary.cpp.

958  :QObject(parent), d(0), did_load(false)
959 {
960 }
QLibraryPrivate * d
Definition: qlibrary.h:108
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
bool did_load
Definition: qlibrary.h:109

◆ QLibrary() [2/4]

QLibrary::QLibrary ( const QString fileName,
QObject parent = 0 
)
explicit

Constructs a library object with the given parent that will load the library specified by fileName.

We recommend omitting the file's suffix in fileName, since QLibrary will automatically look for the file with the appropriate suffix in accordance with the platform, e.g. ".so" on Unix, ".dylib" on Mac OS X, and ".dll" on Windows. (See fileName.)

Note: In Symbian the path portion of the fileName is ignored.

Definition at line 974 of file qlibrary.cpp.

975  :QObject(parent), d(0), did_load(false)
976 {
977  setFileName(fileName);
978 }
void setFileName(const QString &fileName)
Definition: qlibrary.cpp:1058
QLibraryPrivate * d
Definition: qlibrary.h:108
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
bool did_load
Definition: qlibrary.h:109

◆ QLibrary() [3/4]

QLibrary::QLibrary ( const QString fileName,
int  verNum,
QObject parent = 0 
)
explicit

Constructs a library object with the given parent that will load the library specified by fileName and major version number verNum.

Currently, the version number is ignored on Windows and Symbian.

We recommend omitting the file's suffix in fileName, since QLibrary will automatically look for the file with the appropriate suffix in accordance with the platform, e.g. ".so" on Unix, ".dylib" on Mac OS X, and ".dll" on Windows. (See fileName.)

Note: In Symbian the path portion of the fileName is ignored.

Definition at line 993 of file qlibrary.cpp.

994  :QObject(parent), d(0), did_load(false)
995 {
996  setFileNameAndVersion(fileName, verNum);
997 }
void setFileNameAndVersion(const QString &fileName, int verNum)
Sets the fileName property and major version number to fileName and versionNumber respectively...
Definition: qlibrary.cpp:1092
QLibraryPrivate * d
Definition: qlibrary.h:108
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
bool did_load
Definition: qlibrary.h:109

◆ QLibrary() [4/4]

QLibrary::QLibrary ( const QString fileName,
const QString version,
QObject parent = 0 
)
explicit

Constructs a library object with the given parent that will load the library specified by fileName and full version number version.

Currently, the version number is ignored on Windows and Symbian.

We recommend omitting the file's suffix in fileName, since QLibrary will automatically look for the file with the appropriate suffix in accordance with the platform, e.g. ".so" on Unix, ".dylib" on Mac OS X, and ".dll" on Windows. (See fileName.)

Note: In Symbian the path portion of the fileName is ignored.

Definition at line 1011 of file qlibrary.cpp.

1012  :QObject(parent), d(0), did_load(false)
1013 {
1014  setFileNameAndVersion(fileName, version);
1015 }
void setFileNameAndVersion(const QString &fileName, int verNum)
Sets the fileName property and major version number to fileName and versionNumber respectively...
Definition: qlibrary.cpp:1092
QLibraryPrivate * d
Definition: qlibrary.h:108
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
bool did_load
Definition: qlibrary.h:109

◆ ~QLibrary()

QLibrary::~QLibrary ( )

Destroys the QLibrary object.

Unless unload() was called explicitly, the library stays in memory until the application terminates.

See also
isLoaded(), unload()

Definition at line 1025 of file qlibrary.cpp.

1026 {
1027  if (d)
1028  d->release();
1029 }
QLibraryPrivate * d
Definition: qlibrary.h:108

Functions

◆ errorString()

QString QLibrary::errorString ( ) const

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

Since
4.2

Currently, errorString will only be set if load(), unload() or resolve() for some reason fails.

Definition at line 1267 of file qlibrary.cpp.

Referenced by qt_initIcu().

1268 {
1269  return (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString;
1270 }
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QLibraryPrivate * d
Definition: qlibrary.h:108
QString errorString
Definition: qlibrary_p.h:99

◆ fileName()

QString QLibrary::fileName ( ) const

Referenced by setFileName().

◆ isLibrary()

bool QLibrary::isLibrary ( const QString fileName)
static

Returns true if fileName has a valid suffix for a loadable library; otherwise returns false.

Platform Valid suffixes
Windows .dll, .DLL
Unix/Linux .so
AIX .a
HP-UX .sl, .so (HP-UXi)
Mac OS X .dylib, .bundle, .so
Symbian .dll

Trailing versioning numbers on Unix are ignored.

Definition at line 559 of file qlibrary.cpp.

560 {
561 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
562  return fileName.endsWith(QLatin1String(".dll"), Qt::CaseInsensitive);
563 #elif defined(Q_OS_SYMBIAN)
564  // Plugin stubs are also considered libraries in Symbian.
565  return (fileName.endsWith(QLatin1String(".dll")) ||
566  fileName.endsWith(QLatin1String(".qtplugin")));
567 #else
568  QString completeSuffix = QFileInfo(fileName).completeSuffix();
569  if (completeSuffix.isEmpty())
570  return false;
571  QStringList suffixes = completeSuffix.split(QLatin1Char('.'));
572 # if defined(Q_OS_DARWIN)
573 
574  // On Mac, libs look like libmylib.1.0.0.dylib
575  const QString lastSuffix = suffixes.at(suffixes.count() - 1);
576  const QString firstSuffix = suffixes.at(0);
577 
578  bool valid = (lastSuffix == QLatin1String("dylib")
579  || firstSuffix == QLatin1String("so")
580  || firstSuffix == QLatin1String("bundle"));
581 
582  return valid;
583 # else // Generic Unix
584  QStringList validSuffixList;
585 
586 # if defined(Q_OS_HPUX)
587 /*
588  See "HP-UX Linker and Libraries User's Guide", section "Link-time Differences between PA-RISC and IPF":
589  "In PA-RISC (PA-32 and PA-64) shared libraries are suffixed with .sl. In IPF (32-bit and 64-bit),
590  the shared libraries are suffixed with .so. For compatibility, the IPF linker also supports the .sl suffix."
591  */
592  validSuffixList << QLatin1String("sl");
593 # if defined __ia64
594  validSuffixList << QLatin1String("so");
595 # endif
596 # elif defined(Q_OS_AIX)
597  validSuffixList << QLatin1String("a") << QLatin1String("so");
598 # elif defined(Q_OS_UNIX)
599  validSuffixList << QLatin1String("so");
600 # endif
601 
602  // Examples of valid library names:
603  // libfoo.so
604  // libfoo.so.0
605  // libfoo.so.0.3
606  // libfoo-0.3.so
607  // libfoo-0.3.so.0.3.0
608 
609  int suffix;
610  int suffixPos = -1;
611  for (suffix = 0; suffix < validSuffixList.count() && suffixPos == -1; ++suffix)
612  suffixPos = suffixes.indexOf(validSuffixList.at(suffix));
613 
614  bool valid = suffixPos != -1;
615  for (int i = suffixPos + 1; i < suffixes.count() && valid; ++i)
616  if (i != suffixPos)
617  suffixes.at(i).toInt(&valid);
618  return valid;
619 # endif
620 #endif
621 
622 }
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
Definition: qstring.cpp:6090
QString completeSuffix() const
Returns the complete suffix of the file.
Definition: qfileinfo.cpp:811
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
int indexOf(const QRegExp &rx, int from=0) const
Returns the index position of the first exact match of rx in the list, searching forward from index p...
Definition: qstringlist.h:195
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
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 QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray suffix
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ isLoaded()

bool QLibrary::isLoaded ( ) const

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

See also
load()

Definition at line 948 of file qlibrary.cpp.

Referenced by qdbus_loadLibDBus(), qt_init(), and resolve().

949 {
950  return d && d->pHnd;
951 }
HINSTANCE pHnd
Definition: qlibrary_p.h:81
QLibraryPrivate * d
Definition: qlibrary.h:108

◆ load()

bool QLibrary::load ( )

Loads the library and returns true if the library was loaded successfully; otherwise returns false.

Since resolve() always calls this function before resolving any symbols it is not necessary to call it explicitly. In some situations you might want the library loaded in advance, in which case you would use this function.

See also
unload()

Definition at line 909 of file qlibrary.cpp.

Referenced by QApplicationPrivate::construct(), QSslSocketPrivate::ensureCiphersAndCertsLoaded(), loadOpenSslWin32(), qdbus_loadLibDBus(), qt_init(), qt_initIcu(), resolve(), resolveCups(), and resolveLibrary().

910 {
911  if (!d)
912  return false;
913  if (did_load)
914  return d->pHnd;
915  did_load = true;
916  return d->load();
917 }
HINSTANCE pHnd
Definition: qlibrary_p.h:81
QLibraryPrivate * d
Definition: qlibrary.h:108
bool did_load
Definition: qlibrary.h:109

◆ loadHints()

LoadHints QLibrary::loadHints ( ) const

Referenced by setLoadHints().

◆ resolve() [1/4]

void * QLibrary::resolve ( const char *  symbol)

Returns the address of the exported symbol symbol.

The library is loaded if necessary. The function returns 0 if the symbol could not be resolved or if the library could not be loaded.

Example:

typedef int (*AvgFunction)(int, int);
AvgFunction avg = (AvgFunction) library->resolve("avg");
if (avg)
return avg(5, 8);
else
return -1;

The symbol must be exported as a C function from the library. This means that the function must be wrapped in an extern "C" if the library is compiled with a C++ compiler. On Windows you must also explicitly export the function from the DLL using the __declspec(dllexport) compiler directive, for example:

extern "C" MY_EXPORT int avg(int a, int b)
{
return (a + b) / 2;
}

with MY_EXPORT defined as

#ifdef Q_WS_WIN
#define MY_EXPORT __declspec(dllexport)
#else
#define MY_EXPORT
#endif

Note: In Symbian resolving with symbol names works only if the loaded library was built as STDDLL. Otherwise, the ordinals must be used.

Definition at line 1155 of file qlibrary.cpp.

Referenced by QMacPasteboardMimeHTMLText::convertFromMime(), QSslSocketPrivate::ensureCiphersAndCertsLoaded(), QGtkStylePrivate::getIconThemeName(), QGLXContext::getProcAddress(), getTransformationFunction(), HB_Library_Resolve(), qdbus_loadLibDBus(), qdbus_resolve_conditionally(), qdbus_resolve_me(), qgl_use_font(), qglx_getProcAddress(), QGLXContext::QGLXContext(), QIconvCodec::QIconvCodec(), QMacStylePrivate::QMacStylePrivate(), qt_init(), qt_initIcu(), qt_load_library_runtime(), qt_retrieveNisPrinters(), resolve(), resolveAygLibs(), resolveCups(), resolveGConf(), QGtkStylePrivate::resolveGtk(), resolveLibrary(), and resolveOpenGLSymbols().

1156 {
1157  if (!isLoaded() && !load())
1158  return 0;
1159  return d->resolve(symbol);
1160 }
void * resolve(const char *)
Definition: qlibrary.cpp:459
bool isLoaded() const
Returns true if the library is loaded; otherwise returns false.
Definition: qlibrary.cpp:948
QLibraryPrivate * d
Definition: qlibrary.h:108
bool load()
Loads the library and returns true if the library was loaded successfully; otherwise returns false...
Definition: qlibrary.cpp:909

◆ resolve() [2/4]

void * QLibrary::resolve ( const QString fileName,
const char *  symbol 
)
static

Loads the library fileName and returns the address of the exported symbol symbol.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note that fileName should not include the platform-specific file suffix; (see fileName). The library remains loaded until the application exits.

The function returns 0 if the symbol could not be resolved or if the library could not be loaded.

Note: In Symbian resolving with symbol names works only if the loaded library was built as STDDLL. Otherwise, the ordinals must be used.

See also
resolve()

Definition at line 1181 of file qlibrary.cpp.

1182 {
1183  QLibrary library(fileName);
1184  return library.resolve(symbol);
1185 }
The QLibrary class loads shared libraries at runtime.
Definition: qlibrary.h:62

◆ resolve() [3/4]

void * QLibrary::resolve ( const QString fileName,
int  verNum,
const char *  symbol 
)
static

Loads the library fileName with major version number verNum and returns the address of the exported symbol symbol.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Note that fileName should not include the platform-specific file suffix; (see fileName). The library remains loaded until the application exits. verNum is ignored on Windows.

The function returns 0 if the symbol could not be resolved or if the library could not be loaded.

Note: In Symbian resolving with symbol names works only if the loaded library was built as STDDLL. Otherwise, the ordinals must be used.

See also
resolve()

Definition at line 1207 of file qlibrary.cpp.

1208 {
1209  QLibrary library(fileName, verNum);
1210  return library.resolve(symbol);
1211 }
The QLibrary class loads shared libraries at runtime.
Definition: qlibrary.h:62

◆ resolve() [4/4]

void * QLibrary::resolve ( const QString fileName,
const QString version,
const char *  symbol 
)
static

Loads the library fileName with full version number version and returns the address of the exported symbol symbol.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.4

Note that fileName should not include the platform-specific file suffix; (see fileName). The library remains loaded until the application exits. version is ignored on Windows.

The function returns 0 if the symbol could not be resolved or if the library could not be loaded.

Note: In Symbian resolving with symbol names works only if the loaded library was built as STDDLL. Otherwise, the ordinals must be used.

See also
resolve()

Definition at line 1234 of file qlibrary.cpp.

1235 {
1236  QLibrary library(fileName, version);
1237  return library.resolve(symbol);
1238 }
The QLibrary class loads shared libraries at runtime.
Definition: qlibrary.h:62

◆ setFileName()

void QLibrary::setFileName ( const QString fileName)

Definition at line 1058 of file qlibrary.cpp.

Referenced by qdbus_loadLibDBus(), QLibrary(), and qt_init().

1059 {
1060  QLibrary::LoadHints lh;
1061  if (d) {
1062  lh = d->loadHints;
1063  d->release();
1064  d = 0;
1065  did_load = false;
1066  }
1067  d = QLibraryPrivate::findOrCreate(fileName);
1068  d->loadHints = lh;
1069 }
static QLibraryPrivate * findOrCreate(const QString &fileName, const QString &version=QString())
Definition: qlibrary.cpp:438
QLibraryPrivate * d
Definition: qlibrary.h:108
bool did_load
Definition: qlibrary.h:109
QLibrary::LoadHints loadHints
Definition: qlibrary_p.h:100

◆ setFileNameAndVersion() [1/2]

void QLibrary::setFileNameAndVersion ( const QString fileName,
int  versionNumber 
)

Sets the fileName property and major version number to fileName and versionNumber respectively.

The versionNumber is ignored on Windows and Symbian.

Note: In Symbian the path portion of the fileName is ignored.

See also
setFileName()

Definition at line 1092 of file qlibrary.cpp.

Referenced by loadOpenSslWin32(), qdbus_loadLibDBus(), and QLibrary().

1093 {
1094  QLibrary::LoadHints lh;
1095  if (d) {
1096  lh = d->loadHints;
1097  d->release();
1098  d = 0;
1099  did_load = false;
1100  }
1101  d = QLibraryPrivate::findOrCreate(fileName, verNum >= 0 ? QString::number(verNum) : QString());
1102  d->loadHints = lh;
1103 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
static QLibraryPrivate * findOrCreate(const QString &fileName, const QString &version=QString())
Definition: qlibrary.cpp:438
The QString class provides a Unicode character string.
Definition: qstring.h:83
QLibraryPrivate * d
Definition: qlibrary.h:108
bool did_load
Definition: qlibrary.h:109
QLibrary::LoadHints loadHints
Definition: qlibrary_p.h:100

◆ setFileNameAndVersion() [2/2]

void QLibrary::setFileNameAndVersion ( const QString fileName,
const QString version 
)

Sets the fileName property and full version number to fileName and version respectively.

Since
4.4

The version parameter is ignored on Windows and Symbian.

Note: In Symbian the path portion of the fileName is ignored.

See also
setFileName()

Definition at line 1119 of file qlibrary.cpp.

1120 {
1121  QLibrary::LoadHints lh;
1122  if (d) {
1123  lh = d->loadHints;
1124  d->release();
1125  d = 0;
1126  did_load = false;
1127  }
1128  d = QLibraryPrivate::findOrCreate(fileName, version);
1129  d->loadHints = lh;
1130 }
static QLibraryPrivate * findOrCreate(const QString &fileName, const QString &version=QString())
Definition: qlibrary.cpp:438
QLibraryPrivate * d
Definition: qlibrary.h:108
bool did_load
Definition: qlibrary.h:109
QLibrary::LoadHints loadHints
Definition: qlibrary_p.h:100

◆ setLoadHints()

void QLibrary::setLoadHints ( LoadHints  hints)

Definition at line 1304 of file qlibrary.cpp.

Referenced by QGtkStylePrivate::getIconThemeName(), loadOpenSslWin32(), qdbus_loadLibDBus(), qgl_use_font(), qglx_getProcAddress(), QIconvCodec::QIconvCodec(), QMacStylePrivate::QMacStylePrivate(), qt_init(), qt_initIcu(), qt_load_library_runtime(), QGtkStylePrivate::resolveGtk(), and resolveLibrary().

1305 {
1306  if (!d) {
1307  d = QLibraryPrivate::findOrCreate(QString()); // ugly, but we need a d-ptr
1308  d->errorString.clear();
1309  }
1310  d->loadHints = hints;
1311 }
static QLibraryPrivate * findOrCreate(const QString &fileName, const QString &version=QString())
Definition: qlibrary.cpp:438
The QString class provides a Unicode character string.
Definition: qstring.h:83
QLibraryPrivate * d
Definition: qlibrary.h:108
QString errorString
Definition: qlibrary_p.h:99
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
QLibrary::LoadHints loadHints
Definition: qlibrary_p.h:100

◆ unload()

bool QLibrary::unload ( )

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

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

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

Note that on Mac OS X 10.3 (Panther), dynamic libraries cannot be unloaded.

See also
resolve(), load()

Definition at line 934 of file qlibrary.cpp.

Referenced by loadOpenSslWin32(), and qdbus_loadLibDBus().

935 {
936  if (did_load) {
937  did_load = false;
938  return d->unload();
939  }
940  return false;
941 }
QLibraryPrivate * d
Definition: qlibrary.h:108
bool did_load
Definition: qlibrary.h:109

Properties

◆ d

QLibraryPrivate* QLibrary::d
private

◆ did_load

bool QLibrary::did_load
private

Definition at line 109 of file qlibrary.h.

Referenced by setFileName(), and setFileNameAndVersion().

◆ fileName

QString QLibrary::fileName
private

the file name of the library

We recommend omitting the file's suffix in the file name, since QLibrary will automatically look for the file with the appropriate suffix (see isLibrary()).

When loading the library, QLibrary searches in all system-specific library locations (e.g. LD_LIBRARY_PATH on Unix), unless the file name has an absolute path. After loading the library successfully, fileName() returns the fully-qualified file name of the library, including the full path to the library if one was given in the constructor or passed to setFileName().

For example, after successfully loading the "GL" library on Unix platforms, fileName() will return "libGL.so". If the file name was originally passed as "/usr/lib/libGL", fileName() will return "/usr/lib/libGL.so".

Note: In Symbian the path portion of the fileName is ignored.

Definition at line 65 of file qlibrary.h.

Referenced by qdbus_loadLibDBus().

◆ loadHints

QLibrary::LoadHints QLibrary::loadHints
private

Give the load() function some hints on how it should behave.

You can give some hints on how the symbols are resolved. Usually, the symbols are not resolved at load time, but resolved lazily, (that is, when resolve() is called). If you set the loadHint to ResolveAllSymbolsHint, then all symbols will be resolved at load time if the platform supports it.

Setting ExportExternalSymbolsHint will make the external symbols in the library available for resolution in subsequent loaded libraries.

If LoadArchiveMemberHint is set, the file name is composed of two components: A path which is a reference to an archive file followed by the second component which is the reference to the archive member. For instance, the fileName libGL.a(shr_64.o) will refer to the library shr_64.o in the archive file named libGL.a. This is only supported on the AIX platform.

The interpretation of the load hints is platform dependent, and if you use it you are probably making some assumptions on which platform you are compiling for, so use them only if you understand the consequences of them.

By default, none of these flags are set, so libraries will be loaded with lazy symbol resolution, and will not export external symbols for resolution in other dynamically-loaded libraries.

Definition at line 66 of file qlibrary.h.

Referenced by loadOpenSslWin32().


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