summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/qlibrary.3qt
blob: a93e6e7133db702b430352ea8db6ea42b95d20a5 (plain)
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
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 <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 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/qlibrary.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 qt-bugs@trolltech.com .
Please include the name of the manual page (qlibrary.3qt) and the Qt
version (3.3.8).