1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
'\" t
.TH QLibrary 3qt "18 March 2002" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2001 Trolltech AS. 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
\fC#include <qlibrary.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 e.g. 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 become a null pointer. Upon destruction of the QLibrary object 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 = (MyProtoype) myLib.resolve( "mysymbol" );
.br
if ( myFunction ) {
.br
myFunction();
.br
}
.br
.fi
.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. 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 is exited.
.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
.PP
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 this function explicitly. In some situations you might want the library loaded in advance, in which case you would call this function.
.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 a null pointer 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
.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 a null pointer 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( "foo", "function" );
.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/qlibrary.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2001 Trolltech AS, 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 qt-bugs@trolltech.com .
Please include the name of the manual page (qlibrary.3qt) and the Qt
version (3.0.3).
|