diff options
Diffstat (limited to 'doc/man/man3/tqlibrary.3qt')
-rw-r--r-- | doc/man/man3/tqlibrary.3qt | 280 |
1 files changed, 280 insertions, 0 deletions
diff --git a/doc/man/man3/tqlibrary.3qt b/doc/man/man3/tqlibrary.3qt new file mode 100644 index 000000000..5a9293043 --- /dev/null +++ b/doc/man/man3/tqlibrary.3qt @@ -0,0 +1,280 @@ +'\" t +.TH QLibrary 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- +.\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the +.\" license file included in the distribution for a complete license +.\" statement. +.\" +.ad l +.nh +.SH NAME +QLibrary \- Wrapper for handling shared libraries +.SH SYNOPSIS +All the functions in this class are reentrant when Qt is built with thread support.</p> +.PP +\fC#include <ntqlibrary.h>\fR +.PP +.SS "Public Members" +.in +1c +.ti -1c +.BI "\fBQLibrary\fR ( const QString & filename )" +.br +.ti -1c +.BI "virtual \fB~QLibrary\fR ()" +.br +.ti -1c +.BI "void * \fBresolve\fR ( const char * symb )" +.br +.ti -1c +.BI "bool \fBload\fR ()" +.br +.ti -1c +.BI "virtual bool \fBunload\fR ()" +.br +.ti -1c +.BI "bool \fBisLoaded\fR () const" +.br +.ti -1c +.BI "bool \fBautoUnload\fR () const" +.br +.ti -1c +.BI "void \fBsetAutoUnload\fR ( bool enabled )" +.br +.ti -1c +.BI "QString \fBlibrary\fR () const" +.br +.in -1c +.SS "Static Public Members" +.in +1c +.ti -1c +.BI "void * \fBresolve\fR ( const QString & filename, const char * symb )" +.br +.in -1c +.SH DESCRIPTION +The QLibrary class provides a wrapper for handling shared libraries. +.PP +An instance of a QLibrary object can handle a single shared library and provide access to the functionality in the library in a platform independent way. If the library is a component server, QLibrary provides access to the exported component and can directly query this component for interfaces. +.PP +QLibrary ensures that the shared library is loaded and stays in memory whilst it is in use. QLibrary can also unload the library on destruction and release unused resources. +.PP +A typical use of QLibrary is to resolve an exported symbol in a shared object, and to call the 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. +.PP +The following code snippet loads a library, resolves the symbol" mysymbol", and calls the function if everything succeeded. If something went 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. When the QLibrary object is destroyed the library will be unloaded, making all references to memory allocated in the library invalid. +.PP +.nf +.br + typedef void (*MyPrototype)(); +.br + MyPrototype myFunction; +.br +.br + QLibrary myLib( "mylib" ); +.br + myFunction = (MyPrototype) myLib.resolve( "mysymbol" ); +.br + if ( myFunction ) { +.br + myFunction(); +.br + } +.br +.fi +.PP +See also Plugins. +.SH MEMBER FUNCTION DOCUMENTATION +.SH "QLibrary::QLibrary ( const QString & filename )" +Creates a QLibrary object for the shared library \fIfilename\fR. The library will be unloaded in the destructor. +.PP +Note that \fIfilename\fR does not need to include the (platform specific) file extension, so calling +.PP +.nf +.br + QLibrary lib( "mylib" ); +.br +.fi +is equivalent to calling +.PP +.nf +.br + QLibrary lib( "mylib.dll" ); +.br +.fi +on Windows, and +.PP +.nf +.br + QLibrary lib( "libmylib.so" ); +.br +.fi +on Unix. Specifying the extension is not recommended, since doing so introduces a platform dependency. +.PP +If \fIfilename\fR does not include a path, the library loader will look for the file in the platform specific search paths. +.PP +See also load(), unload(), and setAutoUnload(). +.SH "QLibrary::~QLibrary ()\fC [virtual]\fR" +Deletes the QLibrary object. +.PP +The library will be unloaded if autoUnload() is TRUE (the default), otherwise it stays in memory until the application exits. +.PP +See also unload() and setAutoUnload(). +.SH "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. +.PP +See also setAutoUnload(). +.SH "bool QLibrary::isLoaded () const" +Returns TRUE if the library is loaded; otherwise returns FALSE. +.PP +See also unload(). +.SH "QString QLibrary::library () const" +Returns the filename of the shared library this QLibrary object handles, including the platform specific file extension. +.PP +For example: +.PP +.nf +.br + QLibrary lib( "mylib" ); +.br + QString str = lib.library(); +.br +.fi +will set \fIstr\fR to "mylib.dll" on Windows, and "libmylib.so" on Linux. +.SH "bool QLibrary::load ()" +Loads the library. 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. +.PP +On Darwin and Mac OS X this function uses code from dlcompat, part of the OpenDarwin project. +.PP +Copyright (c) 2002 Jorge Acereda and Peter O'Gorman +.PP +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: +.PP +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +.PP +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. +.SH "void * QLibrary::resolve ( const char * symb )" +Returns the address of the exported symbol \fIsymb\fR. The library is loaded if necessary. The function returns 0 if the symbol could not be resolved or the library could not be loaded. +.PP +.nf +.br + typedef int (*avgProc)( int, int ); +.br +.br + avgProc avg = (avgProc) library->resolve( "avg" ); +.br + if ( avg ) +.br + return avg( 5, 8 ); +.br + else +.br + return -1; +.br +.fi +.PP +The symbol must be exported as a C-function from the library. This requires the \fCextern "C"\fR notation if the library is compiled with a C++ compiler. On Windows you also have to explicitly export the function from the DLL using the \fC__declspec(dllexport)\fR compiler directive. +.PP +.nf +.br + extern "C" MY_EXPORT_MACRO int avg(int a, int b) +.br + { +.br + return (a + b) / 2; +.br + } +.br +.fi +.PP +with \fCMY_EXPORT\fR defined as +.PP +.nf +.br + #ifdef Q_WS_WIN +.br + # define MY_EXPORT __declspec(dllexport) +.br + #else +.br + # define MY_EXPORT +.br + #endif +.br +.fi +.PP +On Darwin and Mac OS X this function uses code from dlcompat, part of the OpenDarwin project. +.PP +Copyright (c) 2002 Jorge Acereda and Peter O'Gorman +.PP +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: +.PP +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +.PP +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. +.SH "void * QLibrary::resolve ( const QString & filename, const char * symb )\fC [static]\fR" +This is an overloaded member function, provided for convenience. It behaves essentially like the above function. +.PP +Loads the library \fIfilename\fR and returns the address of the exported symbol \fIsymb\fR. Note that like the constructor, \fIfilename\fR does not need to include the (platform specific) file extension. The library remains loaded until the process exits. +.PP +The function returns 0 if the symbol could not be resolved or the library could not be loaded. +.PP +This function is useful only if you want to resolve a single symbol, e.g. a function pointer from a specific library once: +.PP +.nf +.br + typedef void (*FunctionType)(); +.br + static FunctionType *ptrFunction = 0; +.br + static bool triedResolve = FALSE; +.br + if ( !ptrFunction && !triedResolve ) +.br + ptrFunction = QLibrary::resolve( "mylib", "mysymb" ); +.br +.br + if ( ptrFunction ) +.br + ptrFunction(); +.br + else +.br + ... +.br +.fi +.PP +If you want to resolve multiple symbols, use a QLibrary object and call the non-static version of resolve(). +.PP +See also +.SH "void QLibrary::setAutoUnload ( bool enabled )" +If \fIenabled\fR is TRUE (the default), the wrapper object is set to automatically unload the library upon destruction. If \fIenabled\fR is FALSE, the wrapper object is not unloaded unless you explicitly call unload(). +.PP +See also autoUnload(). +.SH "bool QLibrary::unload ()\fC [virtual]\fR" +Unloads the library and returns TRUE if the library could be unloaded; otherwise returns FALSE. +.PP +This function is called by the destructor if autoUnload() is enabled. +.PP +See also resolve(). + +.SH "SEE ALSO" +.BR http://doc.trolltech.com/ntqlibrary.html +.BR http://www.trolltech.com/faq/tech.html +.SH COPYRIGHT +Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the +license file included in the distribution for a complete license +statement. +.SH AUTHOR +Generated automatically from the source code. +.SH BUGS +If you find a bug in Qt, please report it as described in +.BR http://doc.trolltech.com/bughowto.html . +Good bug reports help us to help you. Thank you. +.P +The definitive Qt documentation is provided in HTML format; it is +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. +.P +If you find errors in this manual page, please report them to +.BR [email protected] . +Please include the name of the manual page (tqlibrary.3qt) and the Qt +version (3.3.8). |