QLibrary(3qt)
π QLibrary π
okay so bestie, welcome to the manual page for QLibrary β aka the wrapper for handling shared libraries π
(that's literally the NAME, no cap).
β¨ SYNOPSIS β¨
heads up: every single function in this class is reentrant when Qt is built with thread support. yes, all of them. slay.
#include <qlibrary.h>
π«Ά Public Members
QLibrary ( const QString & filename )
virtual ~QLibrary ()
void * resolve ( const char * symb )
bool load ()
virtual bool unload ()
bool isLoaded () const
bool autoUnload () const
void setAutoUnload ( bool enabled )
QString library () const
π Static Public Members
void * resolve ( const QString & filename, const char * symb )
πΈ DESCRIPTION πΈ
The QLibrary class provides a wrapper for handling shared libraries. That's the whole vibe. One QLibrary object = one shared library, and it hands you the library's functionality in a platform independent way. If the library happens to be a component server, QLibrary gives you access to the exported component and can directly query that component for interfaces. β¨
QLibrary makes sure the shared library is loaded and stays in memory while it's in use. It can also unload the library on destruction and release unused resources. very considerate of it honestly π«Ά
The classic use case? Resolve an exported symbol in a shared object, then call the function that symbol points to. That's called "explicit linking" β as opposed to "implicit linking", which is what the link step in your build process does when it links an executable against a library. iykyk π¦
Here's a snippet that loads a library, resolves the symbol mysymbol, and calls the function if everything went fine. If something went wrong β say the library file doesn't exist, or the symbol isn't defined β the function pointer will be 0 and won't get called. And when the QLibrary object is destroyed, the library gets unloaded, which makes all references to memory allocated in the library invalid π (dramatic but true).
typedef void (*MyPrototype)();
MyPrototype myFunction;
QLibrary myLib( "mylib" );
myFunction = (MyPrototype) myLib.resolve( "mysymbol" );
if ( myFunction ) {
myFunction();
}
See also Plugins.
π MEMBER FUNCTION DOCUMENTATION π
QLibrary::QLibrary ( const QString & filename )
Creates a QLibrary object for the shared library filename. The library will be unloaded in the destructor. periodt π
Important: filename does not need to include the (platform specific) file extension. So calling
QLibrary lib( "mylib" );
is equivalent to calling
QLibrary lib( "mylib.dll" );
on Windows, and
QLibrary lib( "libmylib.so" );
on Unix. Specifying the extension is not recommended, because doing so introduces a platform dependency. don't do it bestie π
If filename doesn't include a path, the library loader will go looking for the file in the platform specific search paths.
See also load(), unload(), and setAutoUnload().
QLibrary::~QLibrary () [virtual]
Deletes the QLibrary object. π
The library will be unloaded if autoUnload() is TRUE (that's the default), otherwise it just stays in memory until the application exits.
See also unload() and setAutoUnload().
bool QLibrary::autoUnload () const
Returns TRUE if the library will be automatically unloaded when this wrapper object is destructed; otherwise returns FALSE. The default is TRUE. β¨
See also setAutoUnload().
bool QLibrary::isLoaded () const
Returns TRUE if the library is loaded; otherwise returns FALSE.
See also unload().
QString QLibrary::library () const
Returns the filename of the shared library this QLibrary object handles, including the platform specific file extension. π¦
Like, for example:
QLibrary lib( "mylib" );
QString str = lib.library();
this sets str to "mylib.dll" on Windows, and "libmylib.so" on Linux. cute right?
bool QLibrary::load ()
Loads the library. π«Ά Since resolve() always calls this function before resolving any symbols, you don't have to call it explicitly. But sometimes you want the library loaded in advance, and in that case β this is your girl.
On Darwin and Mac OS X this function uses code from dlcompat, part of the OpenDarwin project.
Copyright (c) 2002 Jorge Acereda and Peter O'Gorman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
void * QLibrary::resolve ( const char * symb )
Returns the address of the exported symbol symb. The library is loaded if necessary. The function returns 0 if the symbol could not be resolved or the library could not be loaded. π
typedef int (*avgProc)( int, int );
avgProc avg = (avgProc) library->resolve( "avg" );
if ( avg )
return avg( 5, 8 );
else
return -1;
The symbol must be exported as a C-function from the library. That means you need the extern "C" notation if the library was compiled with a C++ compiler. On Windows you also have to explicitly export the function from the DLL using the __declspec(dllexport) compiler directive. no skipping steps bestie π₯
extern "C" MY_EXPORT_MACRO 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
On Darwin and Mac OS X this function uses code from dlcompat, part of the OpenDarwin project.
Copyright (c) 2002 Jorge Acereda and Peter O'Gorman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
void * QLibrary::resolve ( const QString & filename, const char * symb ) [static]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function. π«Ά
Loads the library filename and returns the address of the exported symbol symb. And ngl, same as the constructor: filename does not need to include the (platform specific) file extension. The library stays loaded until the process exits. π
The function returns 0 if the symbol could not be resolved or the library could not be loaded.
This one is only useful if you want to resolve a single symbol β like, a function pointer from a specific library, just once:
typedef void (*FunctionType)();
static FunctionType *ptrFunction = 0;
static bool triedResolve = FALSE;
if ( !ptrFunction && !triedResolve )
ptrFunction = QLibrary::resolve( "mylib", "mysymb" );
if ( ptrFunction )
ptrFunction();
else
...
If you want to resolve multiple symbols, use a QLibrary object and call the non-static version of resolve() instead. π
See also
void QLibrary::setAutoUnload ( bool enabled )
If enabled is TRUE (the default), the wrapper object is set to automatically unload the library upon destruction. If enabled is FALSE, the wrapper object is not unloaded unless you explicitly call unload(). β¨
See also autoUnload().
bool QLibrary::unload () [virtual]
Unloads the library and returns TRUE if the library could be unloaded; otherwise returns FALSE. π¦
This function is called by the destructor if autoUnload() is enabled.
See also resolve().
π SEE ALSO π
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
β AUTHOR β
Generated automatically from the source code.
π BUGS π
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. π«Ά
The definitive Qt documentation is provided in HTML format; it's located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.
If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qlibrary.3qt) and the Qt version (3.3.8). π
and that's the whole thing, bestie β this page came to you from Trolltech AS, dated 2 February 2007, and it's the QLibrary(3qt) manual for Qt version 3.3.8. go load something iconic β¨π
π
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms