Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QLibrary Class Reference

\inmodule QtCore \reentrant More...

#include <qlibrary.h>

+ Inheritance diagram for QLibrary:
+ Collaboration diagram for QLibrary:

Public Types

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

Public Member Functions

 QLibrary (QObject *parent=nullptr)
 Constructs a library with the given parent.
 
 QLibrary (const QString &fileName, QObject *parent=nullptr)
 Constructs a library object with the given parent that will load the library specified by fileName.
 
 QLibrary (const QString &fileName, int verNum, QObject *parent=nullptr)
 Constructs a library object with the given parent that will load the library specified by fileName and major version number verNum.
 
 QLibrary (const QString &fileName, const QString &version, QObject *parent=nullptr)
 Constructs a library object with the given parent that will load the library specified by fileName and full version number version.
 
 ~QLibrary ()
 Destroys the QLibrary object.
 
QFunctionPointer resolve (const char *symbol)
 Returns the address of the exported symbol symbol.
 
bool load ()
 Loads the library and returns true if the library was loaded successfully; otherwise returns false.
 
bool unload ()
 Unloads the library and returns true if the library could be unloaded; otherwise returns false.
 
bool isLoaded () const
 Returns true if load() succeeded; otherwise returns false.
 
void setFileName (const QString &fileName)
 
QString fileName () const
 
void setFileNameAndVersion (const QString &fileName, int verNum)
 Sets the fileName property and major version number to fileName and versionNumber respectively.
 
void setFileNameAndVersion (const QString &fileName, const QString &version)
 
QString errorString () const
 
void setLoadHints (LoadHints hints)
 
LoadHints loadHints () const
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool event (QEvent *event)
 This virtual function receives events to an object and should return true if the event e was recognized and processed.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) 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.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
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.
 

Static Public Member Functions

static QFunctionPointer resolve (const QString &fileName, const char *symbol)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Loads the library fileName and returns the address of the exported symbol symbol.
 
static QFunctionPointer resolve (const QString &fileName, int verNum, const char *symbol)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Loads the library fileName with major version number verNum and returns the address of the exported symbol symbol.
 
static QFunctionPointer resolve (const QString &fileName, const QString &version, const char *symbol)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
static bool isLibrary (const QString &fileName)
 Returns true if fileName has a valid suffix for a loadable library; otherwise returns false.
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 

Properties

QString fileName
 the file name of the library
 
LoadHints loadHints
 Give the load() function some hints on how it should behave.
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Detailed Description

\inmodule QtCore \reentrant

The QLibrary class loads shared libraries at runtime.

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 name is an absolute path then an attempt is made to load this path first. If the file cannot be found, QLibrary tries the name with different platform-specific file prefixes, like "lib" on Unix and Mac, and suffixes, like ".so" on Unix, ".dylib" on the Mac, or ".dll" on Windows.

If the file path is not absolute then QLibrary modifies the search order to try the system-specific prefixes and suffixes first, followed by the file path specified.

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 yet still minimise the number of attempts to find the library.

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.

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 \nullptr and won't be called.

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) QLibrary::resolve("mylib", "mysymbol");
See also
QPluginLoader

Definition at line 16 of file qlibrary.h.

Member Enumeration Documentation

◆ 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.

\value ResolveAllSymbolsHint Causes all symbols in a library to be resolved when it is loaded, not simply when resolve() is called. \value ExportExternalSymbolsHint Exports unresolved and external symbols in the library so that they can be resolved in other dynamically-loaded libraries loaded later. \value 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. \value PreventUnloadHint Prevents the library from being unloaded from the address space if close() is called. The library's static variables are not reinitialized if open() is called at a later time. \value DeepBindHint Instructs the linker to prefer definitions in the loaded library over exported definitions in the loading application when resolving external symbols in the loaded library. This option is only supported on Linux.

See also
loadHints
Enumerator
ResolveAllSymbolsHint 
ExportExternalSymbolsHint 
LoadArchiveMemberHint 
PreventUnloadHint 
DeepBindHint 

Definition at line 22 of file qlibrary.h.

Constructor & Destructor Documentation

◆ QLibrary() [1/4]

QLibrary::QLibrary ( QObject * parent = nullptr)
explicit

Constructs a library with the given parent.

Definition at line 870 of file qlibrary.cpp.

◆ QLibrary() [2/4]

QLibrary::QLibrary ( const QString & fileName,
QObject * parent = nullptr )
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 \macos and iOS, and ".dll" on Windows. (See \l{fileName}.)

Definition at line 884 of file qlibrary.cpp.

References fileName, and setFileName().

+ Here is the call graph for this function:

◆ QLibrary() [3/4]

QLibrary::QLibrary ( const QString & fileName,
int verNum,
QObject * parent = nullptr )
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.

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 \macos and iOS, and ".dll" on Windows. (See \l{fileName}.)

Definition at line 899 of file qlibrary.cpp.

References fileName, and setFileNameAndVersion().

+ Here is the call graph for this function:

◆ QLibrary() [4/4]

QLibrary::QLibrary ( const QString & fileName,
const QString & version,
QObject * parent = nullptr )
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.

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 \macos and iOS, and ".dll" on Windows. (See \l{fileName}.)

Definition at line 914 of file qlibrary.cpp.

References fileName, and setFileNameAndVersion().

+ Here is the call graph for this function:

◆ ~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 928 of file qlibrary.cpp.

References QLibraryPrivate::release().

+ Here is the call graph for this function:

Member Function Documentation

◆ errorString()

QString QLibrary::errorString ( ) const
Since
4.2

Returns a text string with the description of the last error that occurred. Currently, errorString will only be set if load(), unload() or resolve() for some reason fails.

Definition at line 1096 of file qlibrary.cpp.

References QLibraryPrivate::errorString, QString::isEmpty(), QLibraryPrivate::mutex, str, and tr.

+ Here is the call graph for this function:

◆ fileName()

QString QLibrary::fileName ( ) const

Definition at line 960 of file qlibrary.cpp.

References QLibraryPrivate::fileName, QString::isEmpty(), QLibraryPrivate::mutex, and QLibraryPrivate::qualifiedFileName.

+ Here is the call graph for this function:

◆ isLibrary()

bool QLibrary::isLibrary ( const QString & fileName)
static

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

\table \header

  • Platform
  • Valid suffixes \row
  • Windows
  • .dll, .DLL \row
  • Unix/Linux
  • .so \row
  • AIX
  • .a \row
  • HP-UX
  • .sl, .so (HP-UXi) \row
  • \macos and iOS
  • .dylib, .bundle, .so \endtable

Trailing versioning numbers on Unix are ignored.

Definition at line 614 of file qlibrary.cpp.

References q20::ranges::all_of, QSet< T >::begin(), Qt::CaseInsensitive, QFileInfo::completeSuffix(), QString::endsWith(), fileName, QString::isEmpty(), it, ok, qTokenize(), and void.

Referenced by QQmlJSLinter::loadPlugins().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isLoaded()

bool QLibrary::isLoaded ( ) const

Returns true if load() succeeded; otherwise returns false.

Note
Prior to Qt 6.6, this function would return true even without a call to load() if another QLibrary object on the same library had caused it to be loaded.
See also
load()

Definition at line 861 of file qlibrary.cpp.

References QTaggedPointer< T, Tag >::tag().

Referenced by qdbus_loadLibDBus(), and resolve().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 813 of file qlibrary.cpp.

References QLibraryPrivate::load(), QBasicAtomicPointer< X >::loadRelaxed(), QLibraryPrivate::pHnd, QTaggedPointer< T, Tag >::setTag(), and QTaggedPointer< T, Tag >::tag().

Referenced by QAndroidPlatformVulkanInstance::QAndroidPlatformVulkanInstance(), QFFmpeg::precheckDriver(), qdbus_loadLibDBus(), and resolve().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadHints()

QLibrary::LoadHints QLibrary::loadHints ( ) const

Definition at line 1154 of file qlibrary.cpp.

References QLibraryPrivate::loadHints().

+ Here is the call graph for this function:

◆ resolve() [1/4]

QFunctionPointer QLibrary::resolve ( const char * symbol)

Returns the address of the exported symbol symbol.

The library is loaded if necessary. The function returns \nullptr 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_OS_WIN
#define MY_EXPORT __declspec(dllexport)
#else
#define MY_EXPORT
#endif
\inmodule QtCore \reentrant
Definition qlibrary.h:17
QFunctionPointer resolve(const char *symbol)
Returns the address of the exported symbol symbol.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
AvgFunction avg
int(* AvgFunction)(int, int)
[1]
void(* MyPrototype)()
[0]
QLibrary myLib("mylib")
[0]
#define MY_EXPORT
[3]

Definition at line 1023 of file qlibrary.cpp.

References isLoaded(), load(), and QLibraryPrivate::resolve().

Referenced by QBasicPlatformVulkanInstance::init(), qdbus_loadLibDBus(), resolve(), resolve(), and resolve().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolve() [2/4]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Loads the library fileName and returns the address of the exported symbol symbol.

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

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

See also
resolve()

Definition at line 1043 of file qlibrary.cpp.

References fileName, and resolve().

+ Here is the call graph for this function:

◆ resolve() [3/4]

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

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

Loads the library fileName with full version number version and returns the address of the exported symbol symbol. Note that fileName should not include the platform-specific file suffix; (see \l{fileName}). The library remains loaded until the application exits. version is ignored on Windows.

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

See also
resolve()

Definition at line 1084 of file qlibrary.cpp.

References fileName, and resolve().

+ Here is the call graph for this function:

◆ resolve() [4/4]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Loads the library fileName with major version number verNum and returns the address of the exported symbol symbol.

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

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

See also
resolve()

Definition at line 1063 of file qlibrary.cpp.

References fileName, and resolve().

+ Here is the call graph for this function:

◆ setFileName()

void QLibrary::setFileName ( const QString & fileName)

Definition at line 955 of file qlibrary.cpp.

References fileName, and setFileNameAndVersion().

Referenced by QAndroidPlatformVulkanInstance::QAndroidPlatformVulkanInstance(), QLibrary(), and qdbus_loadLibDBus().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFileNameAndVersion() [1/2]

void QLibrary::setFileNameAndVersion ( const QString & fileName,
const QString & version )
Since
4.4

Sets the fileName property and full version number to fileName and version respectively. The version parameter is ignored on Windows.

See also
setFileName()

Definition at line 992 of file qlibrary.cpp.

References fileName, QLibraryPrivate::findOrCreate(), QLibraryPrivate::loadHints(), and QLibraryPrivate::release().

+ Here is the call graph for this function:

◆ setFileNameAndVersion() [2/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.

See also
setFileName()

Definition at line 978 of file qlibrary.cpp.

References fileName, QString::number(), and setFileNameAndVersion().

Referenced by QLibrary(), QLibrary(), qdbus_loadLibDBus(), setFileName(), and setFileNameAndVersion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLoadHints()

void QLibrary::setLoadHints ( LoadHints hints)

Definition at line 1145 of file qlibrary.cpp.

References QString::clear(), QLibraryPrivate::errorString, QLibraryPrivate::findOrCreate(), and QLibraryPrivate::setLoadHints().

Referenced by qdbus_loadLibDBus().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 \macos, dynamic libraries cannot be unloaded. QLibrary::unload() will return true, but the library will remain loaded into the process.

See also
resolve(), load()

Definition at line 843 of file qlibrary.cpp.

References QTaggedPointer< T, Tag >::setTag(), QTaggedPointer< T, Tag >::tag(), and QLibraryPrivate::unload().

Referenced by QFFmpeg::precheckDriver(), and qdbus_loadLibDBus().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Property Documentation

◆ fileName

QLibrary::fileName
readwrite

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 (for example, 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".

Definition at line 19 of file qlibrary.h.

Referenced by QAndroidPlatformVulkanInstance::QAndroidPlatformVulkanInstance(), QLibrary(), QLibrary(), QLibrary(), QBasicPlatformVulkanInstance::init(), isLibrary(), resolve(), resolve(), resolve(), setFileName(), setFileNameAndVersion(), and setFileNameAndVersion().

◆ loadHints

QLibrary::loadHints
readwrite

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 loadHints 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.

Note
Hints can only be cleared when this object is not associated with a file. Hints can only be added once the file name is set (hints will be or'ed with the old hints).
Setting this property after the library has been loaded has no effect and loadHints() will not reflect those changes.
This property is shared among all QLibrary instances that refer to the same library.

Definition at line 20 of file qlibrary.h.


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