1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtCore module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qplatformdefs.h"
|
---|
43 | #include "qstring.h"
|
---|
44 | #include "qvector.h"
|
---|
45 | #include "qlist.h"
|
---|
46 | #include "qthreadstorage.h"
|
---|
47 | #include "qdir.h"
|
---|
48 | #include "qstringlist.h"
|
---|
49 | #include "qdatetime.h"
|
---|
50 |
|
---|
51 | #ifndef QT_NO_QOBJECT
|
---|
52 | #include <private/qthread_p.h>
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | #include <stdio.h>
|
---|
56 | #include <stdlib.h>
|
---|
57 | #include <limits.h>
|
---|
58 | #include <stdarg.h>
|
---|
59 | #include <string.h>
|
---|
60 |
|
---|
61 | #if !defined(Q_OS_WINCE)
|
---|
62 | # include <errno.h>
|
---|
63 | # if defined(Q_CC_MSVC)
|
---|
64 | # include <crtdbg.h>
|
---|
65 | # endif
|
---|
66 | #endif
|
---|
67 |
|
---|
68 | #if defined(Q_OS_VXWORKS)
|
---|
69 | # include <envLib.h>
|
---|
70 | #endif
|
---|
71 |
|
---|
72 | #if defined(Q_CC_MWERKS) && defined(Q_OS_MACX)
|
---|
73 | #include <CoreServices/CoreServices.h>
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | #if defined(Q_OS_SYMBIAN)
|
---|
77 | #include <e32def.h>
|
---|
78 | #include <e32debug.h>
|
---|
79 | #include <f32file.h>
|
---|
80 | #include <e32math.h>
|
---|
81 | # include "private/qcore_symbian_p.h"
|
---|
82 |
|
---|
83 | _LIT(qt_S60Filter, "Series60v?.*.sis");
|
---|
84 | _LIT(qt_S60SystemInstallDir, "z:\\system\\install\\");
|
---|
85 | #endif
|
---|
86 |
|
---|
87 | QT_BEGIN_NAMESPACE
|
---|
88 |
|
---|
89 |
|
---|
90 | /*!
|
---|
91 | \class QFlag
|
---|
92 | \brief The QFlag class is a helper data type for QFlags.
|
---|
93 |
|
---|
94 | It is equivalent to a plain \c int, except with respect to
|
---|
95 | function overloading and type conversions. You should never need
|
---|
96 | to use this class in your applications.
|
---|
97 |
|
---|
98 | \sa QFlags
|
---|
99 | */
|
---|
100 |
|
---|
101 | /*!
|
---|
102 | \fn QFlag::QFlag(int value)
|
---|
103 |
|
---|
104 | Constructs a QFlag object that stores the given \a value.
|
---|
105 | */
|
---|
106 |
|
---|
107 | /*!
|
---|
108 | \fn QFlag::operator int() const
|
---|
109 |
|
---|
110 | Returns the value stored by the QFlag object.
|
---|
111 | */
|
---|
112 |
|
---|
113 | /*!
|
---|
114 | \class QFlags
|
---|
115 | \brief The QFlags class provides a type-safe way of storing
|
---|
116 | OR-combinations of enum values.
|
---|
117 |
|
---|
118 |
|
---|
119 | \ingroup tools
|
---|
120 |
|
---|
121 | The QFlags<Enum> class is a template class, where Enum is an enum
|
---|
122 | type. QFlags is used throughout Qt for storing combinations of
|
---|
123 | enum values.
|
---|
124 |
|
---|
125 | The traditional C++ approach for storing OR-combinations of enum
|
---|
126 | values is to use an \c int or \c uint variable. The inconvenience
|
---|
127 | with this approach is that there's no type checking at all; any
|
---|
128 | enum value can be OR'd with any other enum value and passed on to
|
---|
129 | a function that takes an \c int or \c uint.
|
---|
130 |
|
---|
131 | Qt uses QFlags to provide type safety. For example, the
|
---|
132 | Qt::Alignment type is simply a typedef for
|
---|
133 | QFlags<Qt::AlignmentFlag>. QLabel::setAlignment() takes a
|
---|
134 | Qt::Alignment parameter, which means that any combination of
|
---|
135 | Qt::AlignmentFlag values,or 0, is legal:
|
---|
136 |
|
---|
137 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 0
|
---|
138 |
|
---|
139 | If you try to pass a value from another enum or just a plain
|
---|
140 | integer other than 0, the compiler will report an error. If you
|
---|
141 | need to cast integer values to flags in a untyped fashion, you can
|
---|
142 | use the explicit QFlags constructor as cast operator.
|
---|
143 |
|
---|
144 | If you want to use QFlags for your own enum types, use
|
---|
145 | the Q_DECLARE_FLAGS() and Q_DECLARE_OPERATORS_FOR_FLAGS().
|
---|
146 |
|
---|
147 | Example:
|
---|
148 |
|
---|
149 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 1
|
---|
150 |
|
---|
151 | You can then use the \c MyClass::Options type to store
|
---|
152 | combinations of \c MyClass::Option values.
|
---|
153 |
|
---|
154 | \section1 Flags and the Meta-Object System
|
---|
155 |
|
---|
156 | The Q_DECLARE_FLAGS() macro does not expose the flags to the meta-object
|
---|
157 | system, so they cannot be used by Qt Script or edited in Qt Designer.
|
---|
158 | To make the flags available for these purposes, the Q_FLAGS() macro must
|
---|
159 | be used:
|
---|
160 |
|
---|
161 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp meta-object flags
|
---|
162 |
|
---|
163 | \section1 Naming Convention
|
---|
164 |
|
---|
165 | A sensible naming convention for enum types and associated QFlags
|
---|
166 | types is to give a singular name to the enum type (e.g., \c
|
---|
167 | Option) and a plural name to the QFlags type (e.g., \c Options).
|
---|
168 | When a singular name is desired for the QFlags type (e.g., \c
|
---|
169 | Alignment), you can use \c Flag as the suffix for the enum type
|
---|
170 | (e.g., \c AlignmentFlag).
|
---|
171 |
|
---|
172 | \sa QFlag
|
---|
173 | */
|
---|
174 |
|
---|
175 | /*!
|
---|
176 | \typedef QFlags::enum_type
|
---|
177 |
|
---|
178 | Typedef for the Enum template type.
|
---|
179 | */
|
---|
180 |
|
---|
181 | /*!
|
---|
182 | \fn QFlags::QFlags(const QFlags &other)
|
---|
183 |
|
---|
184 | Constructs a copy of \a other.
|
---|
185 | */
|
---|
186 |
|
---|
187 | /*!
|
---|
188 | \fn QFlags::QFlags(Enum flag)
|
---|
189 |
|
---|
190 | Constructs a QFlags object storing the given \a flag.
|
---|
191 | */
|
---|
192 |
|
---|
193 | /*!
|
---|
194 | \fn QFlags::QFlags(Zero zero)
|
---|
195 |
|
---|
196 | Constructs a QFlags object with no flags set. \a zero must be a
|
---|
197 | literal 0 value.
|
---|
198 | */
|
---|
199 |
|
---|
200 | /*!
|
---|
201 | \fn QFlags::QFlags(QFlag value)
|
---|
202 |
|
---|
203 | Constructs a QFlags object initialized with the given integer \a
|
---|
204 | value.
|
---|
205 |
|
---|
206 | The QFlag type is a helper type. By using it here instead of \c
|
---|
207 | int, we effectively ensure that arbitrary enum values cannot be
|
---|
208 | cast to a QFlags, whereas untyped enum values (i.e., \c int
|
---|
209 | values) can.
|
---|
210 | */
|
---|
211 |
|
---|
212 | /*!
|
---|
213 | \fn QFlags &QFlags::operator=(const QFlags &other)
|
---|
214 |
|
---|
215 | Assigns \a other to this object and returns a reference to this
|
---|
216 | object.
|
---|
217 | */
|
---|
218 |
|
---|
219 | /*!
|
---|
220 | \fn QFlags &QFlags::operator&=(int mask)
|
---|
221 |
|
---|
222 | Performs a bitwise AND operation with \a mask and stores the
|
---|
223 | result in this QFlags object. Returns a reference to this object.
|
---|
224 |
|
---|
225 | \sa operator&(), operator|=(), operator^=()
|
---|
226 | */
|
---|
227 |
|
---|
228 | /*!
|
---|
229 | \fn QFlags &QFlags::operator&=(uint mask)
|
---|
230 |
|
---|
231 | \overload
|
---|
232 | */
|
---|
233 |
|
---|
234 | /*!
|
---|
235 | \fn QFlags &QFlags::operator|=(QFlags other)
|
---|
236 |
|
---|
237 | Performs a bitwise OR operation with \a other and stores the
|
---|
238 | result in this QFlags object. Returns a reference to this object.
|
---|
239 |
|
---|
240 | \sa operator|(), operator&=(), operator^=()
|
---|
241 | */
|
---|
242 |
|
---|
243 | /*!
|
---|
244 | \fn QFlags &QFlags::operator|=(Enum other)
|
---|
245 |
|
---|
246 | \overload
|
---|
247 | */
|
---|
248 |
|
---|
249 | /*!
|
---|
250 | \fn QFlags &QFlags::operator^=(QFlags other)
|
---|
251 |
|
---|
252 | Performs a bitwise XOR operation with \a other and stores the
|
---|
253 | result in this QFlags object. Returns a reference to this object.
|
---|
254 |
|
---|
255 | \sa operator^(), operator&=(), operator|=()
|
---|
256 | */
|
---|
257 |
|
---|
258 | /*!
|
---|
259 | \fn QFlags &QFlags::operator^=(Enum other)
|
---|
260 |
|
---|
261 | \overload
|
---|
262 | */
|
---|
263 |
|
---|
264 | /*!
|
---|
265 | \fn QFlags::operator int() const
|
---|
266 |
|
---|
267 | Returns the value stored in the QFlags object as an integer.
|
---|
268 | */
|
---|
269 |
|
---|
270 | /*!
|
---|
271 | \fn QFlags QFlags::operator|(QFlags other) const
|
---|
272 |
|
---|
273 | Returns a QFlags object containing the result of the bitwise OR
|
---|
274 | operation on this object and \a other.
|
---|
275 |
|
---|
276 | \sa operator|=(), operator^(), operator&(), operator~()
|
---|
277 | */
|
---|
278 |
|
---|
279 | /*!
|
---|
280 | \fn QFlags QFlags::operator|(Enum other) const
|
---|
281 |
|
---|
282 | \overload
|
---|
283 | */
|
---|
284 |
|
---|
285 | /*!
|
---|
286 | \fn QFlags QFlags::operator^(QFlags other) const
|
---|
287 |
|
---|
288 | Returns a QFlags object containing the result of the bitwise XOR
|
---|
289 | operation on this object and \a other.
|
---|
290 |
|
---|
291 | \sa operator^=(), operator&(), operator|(), operator~()
|
---|
292 | */
|
---|
293 |
|
---|
294 | /*!
|
---|
295 | \fn QFlags QFlags::operator^(Enum other) const
|
---|
296 |
|
---|
297 | \overload
|
---|
298 | */
|
---|
299 |
|
---|
300 | /*!
|
---|
301 | \fn QFlags QFlags::operator&(int mask) const
|
---|
302 |
|
---|
303 | Returns a QFlags object containing the result of the bitwise AND
|
---|
304 | operation on this object and \a mask.
|
---|
305 |
|
---|
306 | \sa operator&=(), operator|(), operator^(), operator~()
|
---|
307 | */
|
---|
308 |
|
---|
309 | /*!
|
---|
310 | \fn QFlags QFlags::operator&(uint mask) const
|
---|
311 |
|
---|
312 | \overload
|
---|
313 | */
|
---|
314 |
|
---|
315 | /*!
|
---|
316 | \fn QFlags QFlags::operator&(Enum mask) const
|
---|
317 |
|
---|
318 | \overload
|
---|
319 | */
|
---|
320 |
|
---|
321 | /*!
|
---|
322 | \fn QFlags QFlags::operator~() const
|
---|
323 |
|
---|
324 | Returns a QFlags object that contains the bitwise negation of
|
---|
325 | this object.
|
---|
326 |
|
---|
327 | \sa operator&(), operator|(), operator^()
|
---|
328 | */
|
---|
329 |
|
---|
330 | /*!
|
---|
331 | \fn bool QFlags::operator!() const
|
---|
332 |
|
---|
333 | Returns true if no flag is set (i.e., if the value stored by the
|
---|
334 | QFlags object is 0); otherwise returns false.
|
---|
335 | */
|
---|
336 |
|
---|
337 | /*!
|
---|
338 | \fn bool QFlags::testFlag(Enum flag) const
|
---|
339 | \since 4.2
|
---|
340 |
|
---|
341 | Returns true if the \a flag is set, otherwise false.
|
---|
342 | */
|
---|
343 |
|
---|
344 | /*!
|
---|
345 | \macro Q_DISABLE_COPY(Class)
|
---|
346 | \relates QObject
|
---|
347 |
|
---|
348 | Disables the use of copy constructors and assignment operators
|
---|
349 | for the given \a Class.
|
---|
350 |
|
---|
351 | Instances of subclasses of QObject should not be thought of as
|
---|
352 | values that can be copied or assigned, but as unique identities.
|
---|
353 | This means that when you create your own subclass of QObject
|
---|
354 | (director or indirect), you should \e not give it a copy constructor
|
---|
355 | or an assignment operator. However, it may not enough to simply
|
---|
356 | omit them from your class, because, if you mistakenly write some code
|
---|
357 | that requires a copy constructor or an assignment operator (it's easy
|
---|
358 | to do), your compiler will thoughtfully create it for you. You must
|
---|
359 | do more.
|
---|
360 |
|
---|
361 | The curious user will have seen that the Qt classes derived
|
---|
362 | from QObject typically include this macro in a private section:
|
---|
363 |
|
---|
364 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 43
|
---|
365 |
|
---|
366 | It declares a copy constructor and an assignment operator in the
|
---|
367 | private section, so that if you use them by mistake, the compiler
|
---|
368 | will report an error.
|
---|
369 |
|
---|
370 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 44
|
---|
371 |
|
---|
372 | But even this might not catch absolutely every case. You might be
|
---|
373 | tempted to do something like this:
|
---|
374 |
|
---|
375 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 45
|
---|
376 |
|
---|
377 | First of all, don't do that. Most compilers will generate code that
|
---|
378 | uses the copy constructor, so the privacy violation error will be
|
---|
379 | reported, but your C++ compiler is not required to generate code for
|
---|
380 | this statement in a specific way. It could generate code using
|
---|
381 | \e{neither} the copy constructor \e{nor} the assignment operator we
|
---|
382 | made private. In that case, no error would be reported, but your
|
---|
383 | application would probably crash when you called a member function
|
---|
384 | of \c{w}.
|
---|
385 | */
|
---|
386 |
|
---|
387 | /*!
|
---|
388 | \macro Q_DECLARE_FLAGS(Flags, Enum)
|
---|
389 | \relates QFlags
|
---|
390 |
|
---|
391 | The Q_DECLARE_FLAGS() macro expands to
|
---|
392 |
|
---|
393 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 2
|
---|
394 |
|
---|
395 | \a Enum is the name of an existing enum type, whereas \a Flags is
|
---|
396 | the name of the QFlags<\e{Enum}> typedef.
|
---|
397 |
|
---|
398 | See the QFlags documentation for details.
|
---|
399 |
|
---|
400 | \sa Q_DECLARE_OPERATORS_FOR_FLAGS()
|
---|
401 | */
|
---|
402 |
|
---|
403 | /*!
|
---|
404 | \macro Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
|
---|
405 | \relates QFlags
|
---|
406 |
|
---|
407 | The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global \c
|
---|
408 | operator|() functions for \a Flags, which is of type QFlags<T>.
|
---|
409 |
|
---|
410 | See the QFlags documentation for details.
|
---|
411 |
|
---|
412 | \sa Q_DECLARE_FLAGS()
|
---|
413 | */
|
---|
414 |
|
---|
415 | /*!
|
---|
416 | \headerfile <QtGlobal>
|
---|
417 | \title Global Qt Declarations
|
---|
418 | \ingroup funclists
|
---|
419 |
|
---|
420 | \brief The <QtGlobal> header file includes the fundamental global
|
---|
421 | declarations. It is included by most other Qt header files.
|
---|
422 |
|
---|
423 | The global declarations include \l{types}, \l{functions} and
|
---|
424 | \l{macros}.
|
---|
425 |
|
---|
426 | The type definitions are partly convenience definitions for basic
|
---|
427 | types (some of which guarantee certain bit-sizes on all platforms
|
---|
428 | supported by Qt), partly types related to Qt message handling. The
|
---|
429 | functions are related to generating messages, Qt version handling
|
---|
430 | and comparing and adjusting object values. And finally, some of
|
---|
431 | the declared macros enable programmers to add compiler or platform
|
---|
432 | specific code to their applications, while others are convenience
|
---|
433 | macros for larger operations.
|
---|
434 |
|
---|
435 | \section1 Types
|
---|
436 |
|
---|
437 | The header file declares several type definitions that guarantee a
|
---|
438 | specified bit-size on all platforms supported by Qt for various
|
---|
439 | basic types, for example \l qint8 which is a signed char
|
---|
440 | guaranteed to be 8-bit on all platforms supported by Qt. The
|
---|
441 | header file also declares the \l qlonglong type definition for \c
|
---|
442 | {long long int } (\c __int64 on Windows).
|
---|
443 |
|
---|
444 | Several convenience type definitions are declared: \l qreal for \c
|
---|
445 | double, \l uchar for \c unsigned char, \l uint for \c unsigned
|
---|
446 | int, \l ulong for \c unsigned long and \l ushort for \c unsigned
|
---|
447 | short.
|
---|
448 |
|
---|
449 | Finally, the QtMsgType definition identifies the various messages
|
---|
450 | that can be generated and sent to a Qt message handler;
|
---|
451 | QtMsgHandler is a type definition for a pointer to a function with
|
---|
452 | the signature \c {void myMsgHandler(QtMsgType, const char *)}.
|
---|
453 |
|
---|
454 | \section1 Functions
|
---|
455 |
|
---|
456 | The <QtGlobal> header file contains several functions comparing
|
---|
457 | and adjusting an object's value. These functions take a template
|
---|
458 | type as argument: You can retrieve the absolute value of an object
|
---|
459 | using the qAbs() function, and you can bound a given object's
|
---|
460 | value by given minimum and maximum values using the qBound()
|
---|
461 | function. You can retrieve the minimum and maximum of two given
|
---|
462 | objects using qMin() and qMax() respectively. All these functions
|
---|
463 | return a corresponding template type; the template types can be
|
---|
464 | replaced by any other type.
|
---|
465 |
|
---|
466 | Example:
|
---|
467 |
|
---|
468 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 3
|
---|
469 |
|
---|
470 | <QtGlobal> also contains functions that generate messages from the
|
---|
471 | given string argument: qCritical(), qDebug(), qFatal() and
|
---|
472 | qWarning(). These functions call the message handler with the
|
---|
473 | given message.
|
---|
474 |
|
---|
475 | Example:
|
---|
476 |
|
---|
477 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 4
|
---|
478 |
|
---|
479 | The remaining functions are qRound() and qRound64(), which both
|
---|
480 | accept a \l qreal value as their argument returning the value
|
---|
481 | rounded up to the nearest integer and 64-bit integer respectively,
|
---|
482 | the qInstallMsgHandler() function which installs the given
|
---|
483 | QtMsgHandler, and the qVersion() function which returns the
|
---|
484 | version number of Qt at run-time as a string.
|
---|
485 |
|
---|
486 | \section1 Macros
|
---|
487 |
|
---|
488 | The <QtGlobal> header file provides a range of macros (Q_CC_*)
|
---|
489 | that are defined if the application is compiled using the
|
---|
490 | specified platforms. For example, the Q_CC_SUN macro is defined if
|
---|
491 | the application is compiled using Forte Developer, or Sun Studio
|
---|
492 | C++. The header file also declares a range of macros (Q_OS_*)
|
---|
493 | that are defined for the specified platforms. For example,
|
---|
494 | Q_OS_X11 which is defined for the X Window System.
|
---|
495 |
|
---|
496 | The purpose of these macros is to enable programmers to add
|
---|
497 | compiler or platform specific code to their application.
|
---|
498 |
|
---|
499 | The remaining macros are convenience macros for larger operations:
|
---|
500 | The QT_TRANSLATE_NOOP() and QT_TR_NOOP() macros provide the
|
---|
501 | possibility of marking text for dynamic translation,
|
---|
502 | i.e. translation without changing the stored source text. The
|
---|
503 | Q_ASSERT() and Q_ASSERT_X() enables warning messages of various
|
---|
504 | level of refinement. The Q_FOREACH() and foreach() macros
|
---|
505 | implement Qt's foreach loop.
|
---|
506 |
|
---|
507 | The Q_INT64_C() and Q_UINT64_C() macros wrap signed and unsigned
|
---|
508 | 64-bit integer literals in a platform-independent way. The
|
---|
509 | Q_CHECK_PTR() macro prints a warning containing the source code's
|
---|
510 | file name and line number, saying that the program ran out of
|
---|
511 | memory, if the pointer is 0. The qPrintable() macro represent an
|
---|
512 | easy way of printing text.
|
---|
513 |
|
---|
514 | Finally, the QT_POINTER_SIZE macro expands to the size of a
|
---|
515 | pointer in bytes, and the QT_VERSION and QT_VERSION_STR macros
|
---|
516 | expand to a numeric value or a string, respectively, specifying
|
---|
517 | Qt's version number, i.e the version the application is compiled
|
---|
518 | against.
|
---|
519 |
|
---|
520 | \sa <QtAlgorithms>, QSysInfo
|
---|
521 | */
|
---|
522 |
|
---|
523 | /*!
|
---|
524 | \typedef qreal
|
---|
525 | \relates <QtGlobal>
|
---|
526 |
|
---|
527 | Typedef for \c double on all platforms except for those using CPUs with
|
---|
528 | ARM architectures.
|
---|
529 | On ARM-based platforms, \c qreal is a typedef for \c float for performance
|
---|
530 | reasons.
|
---|
531 | */
|
---|
532 |
|
---|
533 | /*! \typedef uchar
|
---|
534 | \relates <QtGlobal>
|
---|
535 |
|
---|
536 | Convenience typedef for \c{unsigned char}.
|
---|
537 | */
|
---|
538 |
|
---|
539 | /*!
|
---|
540 | \fn qt_set_sequence_auto_mnemonic(bool on)
|
---|
541 | \relates <QtGlobal>
|
---|
542 |
|
---|
543 | Enables automatic mnemonics on Mac if \a on is true; otherwise
|
---|
544 | this feature is disabled.
|
---|
545 |
|
---|
546 | Note that this function is only available on Mac where mnemonics
|
---|
547 | are disabled by default.
|
---|
548 |
|
---|
549 | To access to this function, use an extern declaration:
|
---|
550 | extern void qt_set_sequence_auto_mnemonic(bool b);
|
---|
551 |
|
---|
552 | \sa {QShortcut#mnemonic}{QShortcut}
|
---|
553 | */
|
---|
554 |
|
---|
555 | /*! \typedef ushort
|
---|
556 | \relates <QtGlobal>
|
---|
557 |
|
---|
558 | Convenience typedef for \c{unsigned short}.
|
---|
559 | */
|
---|
560 |
|
---|
561 | /*! \typedef uint
|
---|
562 | \relates <QtGlobal>
|
---|
563 |
|
---|
564 | Convenience typedef for \c{unsigned int}.
|
---|
565 | */
|
---|
566 |
|
---|
567 | /*! \typedef ulong
|
---|
568 | \relates <QtGlobal>
|
---|
569 |
|
---|
570 | Convenience typedef for \c{unsigned long}.
|
---|
571 | */
|
---|
572 |
|
---|
573 | /*! \typedef qint8
|
---|
574 | \relates <QtGlobal>
|
---|
575 |
|
---|
576 | Typedef for \c{signed char}. This type is guaranteed to be 8-bit
|
---|
577 | on all platforms supported by Qt.
|
---|
578 | */
|
---|
579 |
|
---|
580 | /*!
|
---|
581 | \typedef quint8
|
---|
582 | \relates <QtGlobal>
|
---|
583 |
|
---|
584 | Typedef for \c{unsigned char}. This type is guaranteed to
|
---|
585 | be 8-bit on all platforms supported by Qt.
|
---|
586 | */
|
---|
587 |
|
---|
588 | /*! \typedef qint16
|
---|
589 | \relates <QtGlobal>
|
---|
590 |
|
---|
591 | Typedef for \c{signed short}. This type is guaranteed to be
|
---|
592 | 16-bit on all platforms supported by Qt.
|
---|
593 | */
|
---|
594 |
|
---|
595 | /*!
|
---|
596 | \typedef quint16
|
---|
597 | \relates <QtGlobal>
|
---|
598 |
|
---|
599 | Typedef for \c{unsigned short}. This type is guaranteed to
|
---|
600 | be 16-bit on all platforms supported by Qt.
|
---|
601 | */
|
---|
602 |
|
---|
603 | /*! \typedef qint32
|
---|
604 | \relates <QtGlobal>
|
---|
605 |
|
---|
606 | Typedef for \c{signed int}. This type is guaranteed to be 32-bit
|
---|
607 | on all platforms supported by Qt.
|
---|
608 | */
|
---|
609 |
|
---|
610 | /*!
|
---|
611 | \typedef quint32
|
---|
612 | \relates <QtGlobal>
|
---|
613 |
|
---|
614 | Typedef for \c{unsigned int}. This type is guaranteed to
|
---|
615 | be 32-bit on all platforms supported by Qt.
|
---|
616 | */
|
---|
617 |
|
---|
618 | /*! \typedef qint64
|
---|
619 | \relates <QtGlobal>
|
---|
620 |
|
---|
621 | Typedef for \c{long long int} (\c __int64 on Windows). This type
|
---|
622 | is guaranteed to be 64-bit on all platforms supported by Qt.
|
---|
623 |
|
---|
624 | Literals of this type can be created using the Q_INT64_C() macro:
|
---|
625 |
|
---|
626 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 5
|
---|
627 |
|
---|
628 | \sa Q_INT64_C(), quint64, qlonglong
|
---|
629 | */
|
---|
630 |
|
---|
631 | /*!
|
---|
632 | \typedef quint64
|
---|
633 | \relates <QtGlobal>
|
---|
634 |
|
---|
635 | Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
|
---|
636 | Windows). This type is guaranteed to be 64-bit on all platforms
|
---|
637 | supported by Qt.
|
---|
638 |
|
---|
639 | Literals of this type can be created using the Q_UINT64_C()
|
---|
640 | macro:
|
---|
641 |
|
---|
642 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 6
|
---|
643 |
|
---|
644 | \sa Q_UINT64_C(), qint64, qulonglong
|
---|
645 | */
|
---|
646 |
|
---|
647 | /*!
|
---|
648 | \typedef quintptr
|
---|
649 | \relates <QtGlobal>
|
---|
650 |
|
---|
651 | Integral type for representing a pointers (useful for hashing,
|
---|
652 | etc.).
|
---|
653 |
|
---|
654 | Typedef for either quint32 or quint64. This type is guaranteed to
|
---|
655 | be the same size as a pointer on all platforms supported by Qt. On
|
---|
656 | a system with 32-bit pointers, quintptr is a typedef for quint32;
|
---|
657 | on a system with 64-bit pointers, quintptr is a typedef for
|
---|
658 | quint64.
|
---|
659 |
|
---|
660 | Note that quintptr is unsigned. Use qptrdiff for signed values.
|
---|
661 |
|
---|
662 | \sa qptrdiff, quint32, quint64
|
---|
663 | */
|
---|
664 |
|
---|
665 | /*!
|
---|
666 | \typedef qptrdiff
|
---|
667 | \relates <QtGlobal>
|
---|
668 |
|
---|
669 | Integral type for representing pointer differences.
|
---|
670 |
|
---|
671 | Typedef for either qint32 or qint64. This type is guaranteed to be
|
---|
672 | the same size as a pointer on all platforms supported by Qt. On a
|
---|
673 | system with 32-bit pointers, quintptr is a typedef for quint32; on
|
---|
674 | a system with 64-bit pointers, quintptr is a typedef for quint64.
|
---|
675 |
|
---|
676 | Note that qptrdiff is signed. Use quintptr for unsigned values.
|
---|
677 |
|
---|
678 | \sa quintptr, qint32, qint64
|
---|
679 | */
|
---|
680 |
|
---|
681 | /*!
|
---|
682 | \typedef QtMsgHandler
|
---|
683 | \relates <QtGlobal>
|
---|
684 |
|
---|
685 | This is a typedef for a pointer to a function with the following
|
---|
686 | signature:
|
---|
687 |
|
---|
688 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 7
|
---|
689 |
|
---|
690 | \sa QtMsgType, qInstallMsgHandler()
|
---|
691 | */
|
---|
692 |
|
---|
693 | /*!
|
---|
694 | \enum QtMsgType
|
---|
695 | \relates <QtGlobal>
|
---|
696 |
|
---|
697 | This enum describes the messages that can be sent to a message
|
---|
698 | handler (QtMsgHandler). You can use the enum to identify and
|
---|
699 | associate the various message types with the appropriate
|
---|
700 | actions.
|
---|
701 |
|
---|
702 | \value QtDebugMsg
|
---|
703 | A message generated by the qDebug() function.
|
---|
704 | \value QtWarningMsg
|
---|
705 | A message generated by the qWarning() function.
|
---|
706 | \value QtCriticalMsg
|
---|
707 | A message generated by the qCritical() function.
|
---|
708 | \value QtFatalMsg
|
---|
709 | A message generated by the qFatal() function.
|
---|
710 | \value QtSystemMsg
|
---|
711 |
|
---|
712 |
|
---|
713 | \sa QtMsgHandler, qInstallMsgHandler()
|
---|
714 | */
|
---|
715 |
|
---|
716 | /*! \macro qint64 Q_INT64_C(literal)
|
---|
717 | \relates <QtGlobal>
|
---|
718 |
|
---|
719 | Wraps the signed 64-bit integer \a literal in a
|
---|
720 | platform-independent way.
|
---|
721 |
|
---|
722 | Example:
|
---|
723 |
|
---|
724 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 8
|
---|
725 |
|
---|
726 | \sa qint64, Q_UINT64_C()
|
---|
727 | */
|
---|
728 |
|
---|
729 | /*! \macro quint64 Q_UINT64_C(literal)
|
---|
730 | \relates <QtGlobal>
|
---|
731 |
|
---|
732 | Wraps the unsigned 64-bit integer \a literal in a
|
---|
733 | platform-independent way.
|
---|
734 |
|
---|
735 | Example:
|
---|
736 |
|
---|
737 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 9
|
---|
738 |
|
---|
739 | \sa quint64, Q_INT64_C()
|
---|
740 | */
|
---|
741 |
|
---|
742 | /*! \typedef qlonglong
|
---|
743 | \relates <QtGlobal>
|
---|
744 |
|
---|
745 | Typedef for \c{long long int} (\c __int64 on Windows). This is
|
---|
746 | the same as \l qint64.
|
---|
747 |
|
---|
748 | \sa qulonglong, qint64
|
---|
749 | */
|
---|
750 |
|
---|
751 | /*!
|
---|
752 | \typedef qulonglong
|
---|
753 | \relates <QtGlobal>
|
---|
754 |
|
---|
755 | Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
|
---|
756 | Windows). This is the same as \l quint64.
|
---|
757 |
|
---|
758 | \sa quint64, qlonglong
|
---|
759 | */
|
---|
760 |
|
---|
761 | /*! \fn const T &qAbs(const T &value)
|
---|
762 | \relates <QtGlobal>
|
---|
763 |
|
---|
764 | Compares \a value to the 0 of type T and returns the absolute
|
---|
765 | value. Thus if T is \e {double}, then \a value is compared to
|
---|
766 | \e{(double) 0}.
|
---|
767 |
|
---|
768 | Example:
|
---|
769 |
|
---|
770 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 10
|
---|
771 | */
|
---|
772 |
|
---|
773 | /*! \fn int qRound(qreal value)
|
---|
774 | \relates <QtGlobal>
|
---|
775 |
|
---|
776 | Rounds \a value to the nearest integer.
|
---|
777 |
|
---|
778 | Example:
|
---|
779 |
|
---|
780 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 11
|
---|
781 | */
|
---|
782 |
|
---|
783 | /*! \fn qint64 qRound64(qreal value)
|
---|
784 | \relates <QtGlobal>
|
---|
785 |
|
---|
786 | Rounds \a value to the nearest 64-bit integer.
|
---|
787 |
|
---|
788 | Example:
|
---|
789 |
|
---|
790 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 12
|
---|
791 | */
|
---|
792 |
|
---|
793 | /*! \fn const T &qMin(const T &value1, const T &value2)
|
---|
794 | \relates <QtGlobal>
|
---|
795 |
|
---|
796 | Returns the minimum of \a value1 and \a value2.
|
---|
797 |
|
---|
798 | Example:
|
---|
799 |
|
---|
800 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 13
|
---|
801 |
|
---|
802 | \sa qMax(), qBound()
|
---|
803 | */
|
---|
804 |
|
---|
805 | /*! \fn const T &qMax(const T &value1, const T &value2)
|
---|
806 | \relates <QtGlobal>
|
---|
807 |
|
---|
808 | Returns the maximum of \a value1 and \a value2.
|
---|
809 |
|
---|
810 | Example:
|
---|
811 |
|
---|
812 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 14
|
---|
813 |
|
---|
814 | \sa qMin(), qBound()
|
---|
815 | */
|
---|
816 |
|
---|
817 | /*! \fn const T &qBound(const T &min, const T &value, const T &max)
|
---|
818 | \relates <QtGlobal>
|
---|
819 |
|
---|
820 | Returns \a value bounded by \a min and \a max. This is equivalent
|
---|
821 | to qMax(\a min, qMin(\a value, \a max)).
|
---|
822 |
|
---|
823 | Example:
|
---|
824 |
|
---|
825 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 15
|
---|
826 |
|
---|
827 | \sa qMin(), qMax()
|
---|
828 | */
|
---|
829 |
|
---|
830 | /*!
|
---|
831 | \typedef Q_INT8
|
---|
832 | \relates <QtGlobal>
|
---|
833 | \compat
|
---|
834 |
|
---|
835 | Use \l qint8 instead.
|
---|
836 | */
|
---|
837 |
|
---|
838 | /*!
|
---|
839 | \typedef Q_UINT8
|
---|
840 | \relates <QtGlobal>
|
---|
841 | \compat
|
---|
842 |
|
---|
843 | Use \l quint8 instead.
|
---|
844 | */
|
---|
845 |
|
---|
846 | /*!
|
---|
847 | \typedef Q_INT16
|
---|
848 | \relates <QtGlobal>
|
---|
849 | \compat
|
---|
850 |
|
---|
851 | Use \l qint16 instead.
|
---|
852 | */
|
---|
853 |
|
---|
854 | /*!
|
---|
855 | \typedef Q_UINT16
|
---|
856 | \relates <QtGlobal>
|
---|
857 | \compat
|
---|
858 |
|
---|
859 | Use \l quint16 instead.
|
---|
860 | */
|
---|
861 |
|
---|
862 | /*!
|
---|
863 | \typedef Q_INT32
|
---|
864 | \relates <QtGlobal>
|
---|
865 | \compat
|
---|
866 |
|
---|
867 | Use \l qint32 instead.
|
---|
868 | */
|
---|
869 |
|
---|
870 | /*!
|
---|
871 | \typedef Q_UINT32
|
---|
872 | \relates <QtGlobal>
|
---|
873 | \compat
|
---|
874 |
|
---|
875 | Use \l quint32 instead.
|
---|
876 | */
|
---|
877 |
|
---|
878 | /*!
|
---|
879 | \typedef Q_INT64
|
---|
880 | \relates <QtGlobal>
|
---|
881 | \compat
|
---|
882 |
|
---|
883 | Use \l qint64 instead.
|
---|
884 | */
|
---|
885 |
|
---|
886 | /*!
|
---|
887 | \typedef Q_UINT64
|
---|
888 | \relates <QtGlobal>
|
---|
889 | \compat
|
---|
890 |
|
---|
891 | Use \l quint64 instead.
|
---|
892 | */
|
---|
893 |
|
---|
894 | /*!
|
---|
895 | \typedef Q_LLONG
|
---|
896 | \relates <QtGlobal>
|
---|
897 | \compat
|
---|
898 |
|
---|
899 | Use \l qint64 instead.
|
---|
900 | */
|
---|
901 |
|
---|
902 | /*!
|
---|
903 | \typedef Q_ULLONG
|
---|
904 | \relates <QtGlobal>
|
---|
905 | \compat
|
---|
906 |
|
---|
907 | Use \l quint64 instead.
|
---|
908 | */
|
---|
909 |
|
---|
910 | /*!
|
---|
911 | \typedef Q_LONG
|
---|
912 | \relates <QtGlobal>
|
---|
913 | \compat
|
---|
914 |
|
---|
915 | Use \c{void *} instead.
|
---|
916 | */
|
---|
917 |
|
---|
918 | /*!
|
---|
919 | \typedef Q_ULONG
|
---|
920 | \relates <QtGlobal>
|
---|
921 | \compat
|
---|
922 |
|
---|
923 | Use \c{void *} instead.
|
---|
924 | */
|
---|
925 |
|
---|
926 | /*! \fn bool qSysInfo(int *wordSize, bool *bigEndian)
|
---|
927 | \relates <QtGlobal>
|
---|
928 |
|
---|
929 | Use QSysInfo::WordSize and QSysInfo::ByteOrder instead.
|
---|
930 | */
|
---|
931 |
|
---|
932 | /*!
|
---|
933 | \fn bool qt_winUnicode()
|
---|
934 | \relates <QtGlobal>
|
---|
935 |
|
---|
936 | This function always returns true.
|
---|
937 |
|
---|
938 | \sa QSysInfo
|
---|
939 | */
|
---|
940 |
|
---|
941 | /*!
|
---|
942 | \fn int qWinVersion()
|
---|
943 | \relates <QtGlobal>
|
---|
944 |
|
---|
945 | Use QSysInfo::WindowsVersion instead.
|
---|
946 |
|
---|
947 | \sa QSysInfo
|
---|
948 | */
|
---|
949 |
|
---|
950 | /*!
|
---|
951 | \fn int qMacVersion()
|
---|
952 | \relates <QtGlobal>
|
---|
953 |
|
---|
954 | Use QSysInfo::MacintoshVersion instead.
|
---|
955 |
|
---|
956 | \sa QSysInfo
|
---|
957 | */
|
---|
958 |
|
---|
959 | /*!
|
---|
960 | \macro QT_VERSION_CHECK
|
---|
961 | \relates <QtGlobal>
|
---|
962 |
|
---|
963 | Turns the major, minor and patch numbers of a version into an
|
---|
964 | integer, 0xMMNNPP (MM = major, NN = minor, PP = patch). This can
|
---|
965 | be compared with another similarly processed version id.
|
---|
966 |
|
---|
967 | \sa QT_VERSION
|
---|
968 | */
|
---|
969 |
|
---|
970 | /*!
|
---|
971 | \macro QT_VERSION
|
---|
972 | \relates <QtGlobal>
|
---|
973 |
|
---|
974 | This macro expands a numeric value of the form 0xMMNNPP (MM =
|
---|
975 | major, NN = minor, PP = patch) that specifies Qt's version
|
---|
976 | number. For example, if you compile your application against Qt
|
---|
977 | 4.1.2, the QT_VERSION macro will expand to 0x040102.
|
---|
978 |
|
---|
979 | You can use QT_VERSION to use the latest Qt features where
|
---|
980 | available.
|
---|
981 |
|
---|
982 | Example:
|
---|
983 |
|
---|
984 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 16
|
---|
985 |
|
---|
986 | \sa QT_VERSION_STR, qVersion()
|
---|
987 | */
|
---|
988 |
|
---|
989 | /*!
|
---|
990 | \macro QT_VERSION_STR
|
---|
991 | \relates <QtGlobal>
|
---|
992 |
|
---|
993 | This macro expands to a string that specifies Qt's version number
|
---|
994 | (for example, "4.1.2"). This is the version against which the
|
---|
995 | application is compiled.
|
---|
996 |
|
---|
997 | \sa qVersion(), QT_VERSION
|
---|
998 | */
|
---|
999 |
|
---|
1000 | /*!
|
---|
1001 | \relates <QtGlobal>
|
---|
1002 |
|
---|
1003 | Returns the version number of Qt at run-time as a string (for
|
---|
1004 | example, "4.1.2"). This may be a different version than the
|
---|
1005 | version the application was compiled against.
|
---|
1006 |
|
---|
1007 | \sa QT_VERSION_STR
|
---|
1008 | */
|
---|
1009 |
|
---|
1010 | const char *qVersion()
|
---|
1011 | {
|
---|
1012 | return QT_VERSION_STR;
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | bool qSharedBuild()
|
---|
1016 | {
|
---|
1017 | #ifdef QT_SHARED
|
---|
1018 | return true;
|
---|
1019 | #else
|
---|
1020 | return false;
|
---|
1021 | #endif
|
---|
1022 | }
|
---|
1023 |
|
---|
1024 | /*****************************************************************************
|
---|
1025 | System detection routines
|
---|
1026 | *****************************************************************************/
|
---|
1027 |
|
---|
1028 | /*!
|
---|
1029 | \class QSysInfo
|
---|
1030 | \brief The QSysInfo class provides information about the system.
|
---|
1031 |
|
---|
1032 | \list
|
---|
1033 | \o \l WordSize specifies the size of a pointer for the platform
|
---|
1034 | on which the application is compiled.
|
---|
1035 | \o \l ByteOrder specifies whether the platform is big-endian or
|
---|
1036 | little-endian.
|
---|
1037 | \o \l WindowsVersion specifies the version of the Windows operating
|
---|
1038 | system on which the application is run (Windows only)
|
---|
1039 | \o \l MacintoshVersion specifies the version of the Macintosh
|
---|
1040 | operating system on which the application is run (Mac only).
|
---|
1041 | \endlist
|
---|
1042 |
|
---|
1043 | Some constants are defined only on certain platforms. You can use
|
---|
1044 | the preprocessor symbols Q_WS_WIN and Q_WS_MAC to test that
|
---|
1045 | the application is compiled under Windows or Mac.
|
---|
1046 |
|
---|
1047 | \sa QLibraryInfo
|
---|
1048 | */
|
---|
1049 |
|
---|
1050 | /*!
|
---|
1051 | \enum QSysInfo::Sizes
|
---|
1052 |
|
---|
1053 | This enum provides platform-specific information about the sizes of data
|
---|
1054 | structures used by the underlying architecture.
|
---|
1055 |
|
---|
1056 | \value WordSize The size in bits of a pointer for the platform on which
|
---|
1057 | the application is compiled (32 or 64).
|
---|
1058 | */
|
---|
1059 |
|
---|
1060 | /*!
|
---|
1061 | \variable QSysInfo::WindowsVersion
|
---|
1062 | \brief the version of the Windows operating system on which the
|
---|
1063 | application is run (Windows only)
|
---|
1064 | */
|
---|
1065 |
|
---|
1066 | /*!
|
---|
1067 | \fn QSysInfo::WindowsVersion QSysInfo::windowsVersion()
|
---|
1068 | \since 4.4
|
---|
1069 |
|
---|
1070 | Returns the version of the Windows operating system on which the
|
---|
1071 | application is run (Windows only).
|
---|
1072 | */
|
---|
1073 |
|
---|
1074 | /*!
|
---|
1075 | \variable QSysInfo::MacintoshVersion
|
---|
1076 | \brief the version of the Macintosh operating system on which
|
---|
1077 | the application is run (Mac only).
|
---|
1078 | */
|
---|
1079 |
|
---|
1080 | /*!
|
---|
1081 | \fn QSysInfo::SymbianVersion QSysInfo::symbianVersion()
|
---|
1082 | \since 4.6
|
---|
1083 |
|
---|
1084 | Returns the version of the Symbian operating system on which the
|
---|
1085 | application is run (Symbian only).
|
---|
1086 | */
|
---|
1087 |
|
---|
1088 | /*!
|
---|
1089 | \fn QSysInfo::S60Version QSysInfo::s60Version()
|
---|
1090 | \since 4.6
|
---|
1091 |
|
---|
1092 | Returns the version of the S60 SDK system on which the
|
---|
1093 | application is run (S60 only).
|
---|
1094 | */
|
---|
1095 |
|
---|
1096 | /*!
|
---|
1097 | \enum QSysInfo::Endian
|
---|
1098 |
|
---|
1099 | \value BigEndian Big-endian byte order (also called Network byte order)
|
---|
1100 | \value LittleEndian Little-endian byte order
|
---|
1101 | \value ByteOrder Equals BigEndian or LittleEndian, depending on
|
---|
1102 | the platform's byte order.
|
---|
1103 | */
|
---|
1104 |
|
---|
1105 | /*!
|
---|
1106 | \enum QSysInfo::WinVersion
|
---|
1107 |
|
---|
1108 | This enum provides symbolic names for the various versions of the
|
---|
1109 | Windows operating system. On Windows, the
|
---|
1110 | QSysInfo::WindowsVersion variable gives the version of the system
|
---|
1111 | on which the application is run.
|
---|
1112 |
|
---|
1113 | MS-DOS-based versions:
|
---|
1114 |
|
---|
1115 | \value WV_32s Windows 3.1 with Win 32s
|
---|
1116 | \value WV_95 Windows 95
|
---|
1117 | \value WV_98 Windows 98
|
---|
1118 | \value WV_Me Windows Me
|
---|
1119 |
|
---|
1120 | NT-based versions (note that each operating system version is only represented once rather than each Windows edition):
|
---|
1121 |
|
---|
1122 | \value WV_NT Windows NT (operating system version 4.0)
|
---|
1123 | \value WV_2000 Windows 2000 (operating system version 5.0)
|
---|
1124 | \value WV_XP Windows XP (operating system version 5.1)
|
---|
1125 | \value WV_2003 Windows Server 2003, Windows Server 2003 R2, Windows Home Server, Windows XP Professional x64 Edition (operating system version 5.2)
|
---|
1126 | \value WV_VISTA Windows Vista, Windows Server 2008 (operating system version 6.0)
|
---|
1127 | \value WV_WINDOWS7 Windows 7, Windows Server 2008 R2 (operating system version 6.1)
|
---|
1128 |
|
---|
1129 | Alternatively, you may use the following macros which correspond directly to the Windows operating system version number:
|
---|
1130 |
|
---|
1131 | \value WV_4_0 Operating system version 4.0, corresponds to Windows NT
|
---|
1132 | \value WV_5_0 Operating system version 5.0, corresponds to Windows 2000
|
---|
1133 | \value WV_5_1 Operating system version 5.1, corresponds to Windows XP
|
---|
1134 | \value WV_5_2 Operating system version 5.2, corresponds to Windows Server 2003, Windows Server 2003 R2, Windows Home Server, and Windows XP Professional x64 Edition
|
---|
1135 | \value WV_6_0 Operating system version 6.0, corresponds to Windows Vista and Windows Server 2008
|
---|
1136 | \value WV_6_1 Operating system version 6.1, corresponds to Windows 7 and Windows Server 2008 R2
|
---|
1137 |
|
---|
1138 | CE-based versions:
|
---|
1139 |
|
---|
1140 | \value WV_CE Windows CE
|
---|
1141 | \value WV_CENET Windows CE .NET
|
---|
1142 | \value WV_CE_5 Windows CE 5.x
|
---|
1143 | \value WV_CE_6 Windows CE 6.x
|
---|
1144 |
|
---|
1145 | The following masks can be used for testing whether a Windows
|
---|
1146 | version is MS-DOS-based, NT-based, or CE-based:
|
---|
1147 |
|
---|
1148 | \value WV_DOS_based MS-DOS-based version of Windows
|
---|
1149 | \value WV_NT_based NT-based version of Windows
|
---|
1150 | \value WV_CE_based CE-based version of Windows
|
---|
1151 |
|
---|
1152 | \sa MacVersion, SymbianVersion
|
---|
1153 | */
|
---|
1154 |
|
---|
1155 | /*!
|
---|
1156 | \enum QSysInfo::MacVersion
|
---|
1157 |
|
---|
1158 | This enum provides symbolic names for the various versions of the
|
---|
1159 | Macintosh operating system. On Mac, the
|
---|
1160 | QSysInfo::MacintoshVersion variable gives the version of the
|
---|
1161 | system on which the application is run.
|
---|
1162 |
|
---|
1163 | \value MV_9 Mac OS 9 (unsupported)
|
---|
1164 | \value MV_10_0 Mac OS X 10.0 (unsupported)
|
---|
1165 | \value MV_10_1 Mac OS X 10.1 (unsupported)
|
---|
1166 | \value MV_10_2 Mac OS X 10.2 (unsupported)
|
---|
1167 | \value MV_10_3 Mac OS X 10.3
|
---|
1168 | \value MV_10_4 Mac OS X 10.4
|
---|
1169 | \value MV_10_5 Mac OS X 10.5
|
---|
1170 | \value MV_10_6 Mac OS X 10.6
|
---|
1171 | \value MV_Unknown An unknown and currently unsupported platform
|
---|
1172 |
|
---|
1173 | \value MV_CHEETAH Apple codename for MV_10_0
|
---|
1174 | \value MV_PUMA Apple codename for MV_10_1
|
---|
1175 | \value MV_JAGUAR Apple codename for MV_10_2
|
---|
1176 | \value MV_PANTHER Apple codename for MV_10_3
|
---|
1177 | \value MV_TIGER Apple codename for MV_10_4
|
---|
1178 | \value MV_LEOPARD Apple codename for MV_10_5
|
---|
1179 | \value MV_SNOWLEOPARD Apple codename for MV_10_6
|
---|
1180 |
|
---|
1181 | \sa WinVersion, SymbianVersion
|
---|
1182 | */
|
---|
1183 |
|
---|
1184 | /*!
|
---|
1185 | \enum QSysInfo::SymbianVersion
|
---|
1186 |
|
---|
1187 | This enum provides symbolic names for the various versions of the
|
---|
1188 | Symbian operating system. On Symbian, the
|
---|
1189 | QSysInfo::symbianVersion() function gives the version of the
|
---|
1190 | system on which the application is run.
|
---|
1191 |
|
---|
1192 | \value SV_9_2 Symbian OS v9.2
|
---|
1193 | \value SV_9_3 Symbian OS v9.3
|
---|
1194 | \value SV_9_4 Symbian OS v9.4
|
---|
1195 | \value SV_SF_1 Symbian^1
|
---|
1196 | \value SV_SF_2 Symbian^2
|
---|
1197 | \value SV_SF_3 Symbian^3
|
---|
1198 | \value SV_SF_4 Symbian^4
|
---|
1199 | \value SV_Unknown An unknown and currently unsupported platform
|
---|
1200 |
|
---|
1201 | \sa S60Version, WinVersion, MacVersion
|
---|
1202 | */
|
---|
1203 |
|
---|
1204 | /*!
|
---|
1205 | \enum QSysInfo::S60Version
|
---|
1206 |
|
---|
1207 | This enum provides symbolic names for the various versions of the
|
---|
1208 | S60 SDK. On S60, the
|
---|
1209 | QSysInfo::s60Version() function gives the version of the
|
---|
1210 | SDK on which the application is run.
|
---|
1211 |
|
---|
1212 | \value SV_S60_3_1 S60 3rd Edition Feature Pack 1
|
---|
1213 | \value SV_S60_3_2 S60 3rd Edition Feature Pack 2
|
---|
1214 | \value SV_S60_5_0 S60 5th Edition
|
---|
1215 | \value SV_S60_5_1 S60 5th Edition Feature Pack 1
|
---|
1216 | \value SV_S60_5_2 S60 5th Edition Feature Pack 2
|
---|
1217 | \value SV_S60_Unknown An unknown and currently unsupported platform
|
---|
1218 | \omitvalue SV_S60_None
|
---|
1219 |
|
---|
1220 | \sa SymbianVersion, WinVersion, MacVersion
|
---|
1221 | */
|
---|
1222 |
|
---|
1223 | /*!
|
---|
1224 | \macro Q_WS_MAC
|
---|
1225 | \relates <QtGlobal>
|
---|
1226 |
|
---|
1227 | Defined on Mac OS X.
|
---|
1228 |
|
---|
1229 | \sa Q_WS_WIN, Q_WS_X11, Q_WS_QWS, Q_WS_S60
|
---|
1230 | */
|
---|
1231 |
|
---|
1232 | /*!
|
---|
1233 | \macro Q_WS_WIN
|
---|
1234 | \relates <QtGlobal>
|
---|
1235 |
|
---|
1236 | Defined on Windows.
|
---|
1237 |
|
---|
1238 | \sa Q_WS_MAC, Q_WS_X11, Q_WS_QWS, Q_WS_S60
|
---|
1239 | */
|
---|
1240 |
|
---|
1241 | /*!
|
---|
1242 | \macro Q_WS_X11
|
---|
1243 | \relates <QtGlobal>
|
---|
1244 |
|
---|
1245 | Defined on X11.
|
---|
1246 |
|
---|
1247 | \sa Q_WS_MAC, Q_WS_WIN, Q_WS_QWS, Q_WS_S60
|
---|
1248 | */
|
---|
1249 |
|
---|
1250 | /*!
|
---|
1251 | \macro Q_WS_QWS
|
---|
1252 | \relates <QtGlobal>
|
---|
1253 |
|
---|
1254 | Defined on Qt for Embedded Linux.
|
---|
1255 |
|
---|
1256 | \sa Q_WS_MAC, Q_WS_WIN, Q_WS_X11, Q_WS_S60
|
---|
1257 | */
|
---|
1258 |
|
---|
1259 | /*!
|
---|
1260 | \macro Q_OS_DARWIN
|
---|
1261 | \relates <QtGlobal>
|
---|
1262 |
|
---|
1263 | Defined on Darwin OS (synonym for Q_OS_MAC).
|
---|
1264 | */
|
---|
1265 |
|
---|
1266 | /*!
|
---|
1267 | \macro Q_OS_MSDOS
|
---|
1268 | \relates <QtGlobal>
|
---|
1269 |
|
---|
1270 | Defined on MS-DOS and Windows.
|
---|
1271 | */
|
---|
1272 |
|
---|
1273 | /*!
|
---|
1274 | \macro Q_OS_OS2
|
---|
1275 | \relates <QtGlobal>
|
---|
1276 |
|
---|
1277 | Defined on OS/2.
|
---|
1278 | */
|
---|
1279 |
|
---|
1280 | /*!
|
---|
1281 | \macro Q_OS_OS2EMX
|
---|
1282 | \relates <QtGlobal>
|
---|
1283 |
|
---|
1284 | Defined on XFree86 on OS/2 (not PM).
|
---|
1285 | */
|
---|
1286 |
|
---|
1287 | /*!
|
---|
1288 | \macro Q_OS_WIN32
|
---|
1289 | \relates <QtGlobal>
|
---|
1290 |
|
---|
1291 | Defined on all supported versions of Windows.
|
---|
1292 | */
|
---|
1293 |
|
---|
1294 | /*!
|
---|
1295 | \macro Q_OS_WINCE
|
---|
1296 | \relates <QtGlobal>
|
---|
1297 |
|
---|
1298 | Defined on Windows CE.
|
---|
1299 | */
|
---|
1300 |
|
---|
1301 | /*!
|
---|
1302 | \macro Q_OS_CYGWIN
|
---|
1303 | \relates <QtGlobal>
|
---|
1304 |
|
---|
1305 | Defined on Cygwin.
|
---|
1306 | */
|
---|
1307 |
|
---|
1308 | /*!
|
---|
1309 | \macro Q_OS_SOLARIS
|
---|
1310 | \relates <QtGlobal>
|
---|
1311 |
|
---|
1312 | Defined on Sun Solaris.
|
---|
1313 | */
|
---|
1314 |
|
---|
1315 | /*!
|
---|
1316 | \macro Q_OS_HPUX
|
---|
1317 | \relates <QtGlobal>
|
---|
1318 |
|
---|
1319 | Defined on HP-UX.
|
---|
1320 | */
|
---|
1321 |
|
---|
1322 | /*!
|
---|
1323 | \macro Q_OS_ULTRIX
|
---|
1324 | \relates <QtGlobal>
|
---|
1325 |
|
---|
1326 | Defined on DEC Ultrix.
|
---|
1327 | */
|
---|
1328 |
|
---|
1329 | /*!
|
---|
1330 | \macro Q_OS_LINUX
|
---|
1331 | \relates <QtGlobal>
|
---|
1332 |
|
---|
1333 | Defined on Linux.
|
---|
1334 | */
|
---|
1335 |
|
---|
1336 | /*!
|
---|
1337 | \macro Q_OS_FREEBSD
|
---|
1338 | \relates <QtGlobal>
|
---|
1339 |
|
---|
1340 | Defined on FreeBSD.
|
---|
1341 | */
|
---|
1342 |
|
---|
1343 | /*!
|
---|
1344 | \macro Q_OS_NETBSD
|
---|
1345 | \relates <QtGlobal>
|
---|
1346 |
|
---|
1347 | Defined on NetBSD.
|
---|
1348 | */
|
---|
1349 |
|
---|
1350 | /*!
|
---|
1351 | \macro Q_OS_OPENBSD
|
---|
1352 | \relates <QtGlobal>
|
---|
1353 |
|
---|
1354 | Defined on OpenBSD.
|
---|
1355 | */
|
---|
1356 |
|
---|
1357 | /*!
|
---|
1358 | \macro Q_OS_BSDI
|
---|
1359 | \relates <QtGlobal>
|
---|
1360 |
|
---|
1361 | Defined on BSD/OS.
|
---|
1362 | */
|
---|
1363 |
|
---|
1364 | /*!
|
---|
1365 | \macro Q_OS_IRIX
|
---|
1366 | \relates <QtGlobal>
|
---|
1367 |
|
---|
1368 | Defined on SGI Irix.
|
---|
1369 | */
|
---|
1370 |
|
---|
1371 | /*!
|
---|
1372 | \macro Q_OS_OSF
|
---|
1373 | \relates <QtGlobal>
|
---|
1374 |
|
---|
1375 | Defined on HP Tru64 UNIX.
|
---|
1376 | */
|
---|
1377 |
|
---|
1378 | /*!
|
---|
1379 | \macro Q_OS_SCO
|
---|
1380 | \relates <QtGlobal>
|
---|
1381 |
|
---|
1382 | Defined on SCO OpenServer 5.
|
---|
1383 | */
|
---|
1384 |
|
---|
1385 | /*!
|
---|
1386 | \macro Q_OS_UNIXWARE
|
---|
1387 | \relates <QtGlobal>
|
---|
1388 |
|
---|
1389 | Defined on UnixWare 7, Open UNIX 8.
|
---|
1390 | */
|
---|
1391 |
|
---|
1392 | /*!
|
---|
1393 | \macro Q_OS_AIX
|
---|
1394 | \relates <QtGlobal>
|
---|
1395 |
|
---|
1396 | Defined on AIX.
|
---|
1397 | */
|
---|
1398 |
|
---|
1399 | /*!
|
---|
1400 | \macro Q_OS_HURD
|
---|
1401 | \relates <QtGlobal>
|
---|
1402 |
|
---|
1403 | Defined on GNU Hurd.
|
---|
1404 | */
|
---|
1405 |
|
---|
1406 | /*!
|
---|
1407 | \macro Q_OS_DGUX
|
---|
1408 | \relates <QtGlobal>
|
---|
1409 |
|
---|
1410 | Defined on DG/UX.
|
---|
1411 | */
|
---|
1412 |
|
---|
1413 | /*!
|
---|
1414 | \macro Q_OS_RELIANT
|
---|
1415 | \relates <QtGlobal>
|
---|
1416 |
|
---|
1417 | Defined on Reliant UNIX.
|
---|
1418 | */
|
---|
1419 |
|
---|
1420 | /*!
|
---|
1421 | \macro Q_OS_DYNIX
|
---|
1422 | \relates <QtGlobal>
|
---|
1423 |
|
---|
1424 | Defined on DYNIX/ptx.
|
---|
1425 | */
|
---|
1426 |
|
---|
1427 | /*!
|
---|
1428 | \macro Q_OS_QNX
|
---|
1429 | \relates <QtGlobal>
|
---|
1430 |
|
---|
1431 | Defined on QNX Neutrino.
|
---|
1432 | */
|
---|
1433 |
|
---|
1434 | /*!
|
---|
1435 | \macro Q_OS_LYNX
|
---|
1436 | \relates <QtGlobal>
|
---|
1437 |
|
---|
1438 | Defined on LynxOS.
|
---|
1439 | */
|
---|
1440 |
|
---|
1441 | /*!
|
---|
1442 | \macro Q_OS_BSD4
|
---|
1443 | \relates <QtGlobal>
|
---|
1444 |
|
---|
1445 | Defined on Any BSD 4.4 system.
|
---|
1446 | */
|
---|
1447 |
|
---|
1448 | /*!
|
---|
1449 | \macro Q_OS_UNIX
|
---|
1450 | \relates <QtGlobal>
|
---|
1451 |
|
---|
1452 | Defined on Any UNIX BSD/SYSV system.
|
---|
1453 | */
|
---|
1454 |
|
---|
1455 | /*!
|
---|
1456 | \macro Q_CC_SYM
|
---|
1457 | \relates <QtGlobal>
|
---|
1458 |
|
---|
1459 | Defined if the application is compiled using Digital Mars C/C++
|
---|
1460 | (used to be Symantec C++).
|
---|
1461 | */
|
---|
1462 |
|
---|
1463 | /*!
|
---|
1464 | \macro Q_CC_MWERKS
|
---|
1465 | \relates <QtGlobal>
|
---|
1466 |
|
---|
1467 | Defined if the application is compiled using Metrowerks
|
---|
1468 | CodeWarrior.
|
---|
1469 | */
|
---|
1470 |
|
---|
1471 | /*!
|
---|
1472 | \macro Q_CC_MSVC
|
---|
1473 | \relates <QtGlobal>
|
---|
1474 |
|
---|
1475 | Defined if the application is compiled using Microsoft Visual
|
---|
1476 | C/C++, Intel C++ for Windows.
|
---|
1477 | */
|
---|
1478 |
|
---|
1479 | /*!
|
---|
1480 | \macro Q_CC_BOR
|
---|
1481 | \relates <QtGlobal>
|
---|
1482 |
|
---|
1483 | Defined if the application is compiled using Borland/Turbo C++.
|
---|
1484 | */
|
---|
1485 |
|
---|
1486 | /*!
|
---|
1487 | \macro Q_CC_WAT
|
---|
1488 | \relates <QtGlobal>
|
---|
1489 |
|
---|
1490 | Defined if the application is compiled using Watcom C++.
|
---|
1491 | */
|
---|
1492 |
|
---|
1493 | /*!
|
---|
1494 | \macro Q_CC_GNU
|
---|
1495 | \relates <QtGlobal>
|
---|
1496 |
|
---|
1497 | Defined if the application is compiled using GNU C++.
|
---|
1498 | */
|
---|
1499 |
|
---|
1500 | /*!
|
---|
1501 | \macro Q_CC_COMEAU
|
---|
1502 | \relates <QtGlobal>
|
---|
1503 |
|
---|
1504 | Defined if the application is compiled using Comeau C++.
|
---|
1505 | */
|
---|
1506 |
|
---|
1507 | /*!
|
---|
1508 | \macro Q_CC_EDG
|
---|
1509 | \relates <QtGlobal>
|
---|
1510 |
|
---|
1511 | Defined if the application is compiled using Edison Design Group
|
---|
1512 | C++.
|
---|
1513 | */
|
---|
1514 |
|
---|
1515 | /*!
|
---|
1516 | \macro Q_CC_OC
|
---|
1517 | \relates <QtGlobal>
|
---|
1518 |
|
---|
1519 | Defined if the application is compiled using CenterLine C++.
|
---|
1520 | */
|
---|
1521 |
|
---|
1522 | /*!
|
---|
1523 | \macro Q_CC_SUN
|
---|
1524 | \relates <QtGlobal>
|
---|
1525 |
|
---|
1526 | Defined if the application is compiled using Forte Developer, or
|
---|
1527 | Sun Studio C++.
|
---|
1528 | */
|
---|
1529 |
|
---|
1530 | /*!
|
---|
1531 | \macro Q_CC_MIPS
|
---|
1532 | \relates <QtGlobal>
|
---|
1533 |
|
---|
1534 | Defined if the application is compiled using MIPSpro C++.
|
---|
1535 | */
|
---|
1536 |
|
---|
1537 | /*!
|
---|
1538 | \macro Q_CC_DEC
|
---|
1539 | \relates <QtGlobal>
|
---|
1540 |
|
---|
1541 | Defined if the application is compiled using DEC C++.
|
---|
1542 | */
|
---|
1543 |
|
---|
1544 | /*!
|
---|
1545 | \macro Q_CC_HPACC
|
---|
1546 | \relates <QtGlobal>
|
---|
1547 |
|
---|
1548 | Defined if the application is compiled using HP aC++.
|
---|
1549 | */
|
---|
1550 |
|
---|
1551 | /*!
|
---|
1552 | \macro Q_CC_USLC
|
---|
1553 | \relates <QtGlobal>
|
---|
1554 |
|
---|
1555 | Defined if the application is compiled using SCO OUDK and UDK.
|
---|
1556 | */
|
---|
1557 |
|
---|
1558 | /*!
|
---|
1559 | \macro Q_CC_CDS
|
---|
1560 | \relates <QtGlobal>
|
---|
1561 |
|
---|
1562 | Defined if the application is compiled using Reliant C++.
|
---|
1563 | */
|
---|
1564 |
|
---|
1565 | /*!
|
---|
1566 | \macro Q_CC_KAI
|
---|
1567 | \relates <QtGlobal>
|
---|
1568 |
|
---|
1569 | Defined if the application is compiled using KAI C++.
|
---|
1570 | */
|
---|
1571 |
|
---|
1572 | /*!
|
---|
1573 | \macro Q_CC_INTEL
|
---|
1574 | \relates <QtGlobal>
|
---|
1575 |
|
---|
1576 | Defined if the application is compiled using Intel C++ for Linux,
|
---|
1577 | Intel C++ for Windows.
|
---|
1578 | */
|
---|
1579 |
|
---|
1580 | /*!
|
---|
1581 | \macro Q_CC_HIGHC
|
---|
1582 | \relates <QtGlobal>
|
---|
1583 |
|
---|
1584 | Defined if the application is compiled using MetaWare High C/C++.
|
---|
1585 | */
|
---|
1586 |
|
---|
1587 | /*!
|
---|
1588 | \macro Q_CC_PGI
|
---|
1589 | \relates <QtGlobal>
|
---|
1590 |
|
---|
1591 | Defined if the application is compiled using Portland Group C++.
|
---|
1592 | */
|
---|
1593 |
|
---|
1594 | /*!
|
---|
1595 | \macro Q_CC_GHS
|
---|
1596 | \relates <QtGlobal>
|
---|
1597 |
|
---|
1598 | Defined if the application is compiled using Green Hills
|
---|
1599 | Optimizing C++ Compilers.
|
---|
1600 | */
|
---|
1601 |
|
---|
1602 | /*!
|
---|
1603 | \macro Q_OS_MAC
|
---|
1604 | \relates <QtGlobal>
|
---|
1605 |
|
---|
1606 | Defined on MAC OS (synonym for Darwin).
|
---|
1607 | */
|
---|
1608 |
|
---|
1609 | /*!
|
---|
1610 | \macro Q_OS_SYMBIAN
|
---|
1611 | \relates <QtGlobal>
|
---|
1612 |
|
---|
1613 | Defined on Symbian.
|
---|
1614 | */
|
---|
1615 |
|
---|
1616 | /*!
|
---|
1617 | \macro Q_WS_S60
|
---|
1618 | \relates <QtGlobal>
|
---|
1619 |
|
---|
1620 | Defined on S60.
|
---|
1621 |
|
---|
1622 | \sa Q_WS_MAC, Q_WS_WIN, Q_WS_X11, Q_WS_QWS
|
---|
1623 | */
|
---|
1624 |
|
---|
1625 | #if defined(QT_BUILD_QMAKE)
|
---|
1626 | // needed to bootstrap qmake
|
---|
1627 | static const unsigned int qt_one = 1;
|
---|
1628 | const int QSysInfo::ByteOrder = ((*((unsigned char *) &qt_one) == 0) ? BigEndian : LittleEndian);
|
---|
1629 | #endif
|
---|
1630 |
|
---|
1631 | #if !defined(QWS) && defined(Q_OS_MAC)
|
---|
1632 |
|
---|
1633 | QT_BEGIN_INCLUDE_NAMESPACE
|
---|
1634 | #include "private/qcore_mac_p.h"
|
---|
1635 | #include "qnamespace.h"
|
---|
1636 | QT_END_INCLUDE_NAMESPACE
|
---|
1637 |
|
---|
1638 | Q_CORE_EXPORT OSErr qt_mac_create_fsref(const QString &file, FSRef *fsref)
|
---|
1639 | {
|
---|
1640 | return FSPathMakeRef(reinterpret_cast<const UInt8 *>(file.toUtf8().constData()), fsref, 0);
|
---|
1641 | }
|
---|
1642 |
|
---|
1643 | // Don't use this function, it won't work in 10.5 (Leopard) and up
|
---|
1644 | Q_CORE_EXPORT OSErr qt_mac_create_fsspec(const QString &file, FSSpec *spec)
|
---|
1645 | {
|
---|
1646 | FSRef fsref;
|
---|
1647 | OSErr ret = qt_mac_create_fsref(file, &fsref);
|
---|
1648 | if (ret == noErr)
|
---|
1649 | ret = FSGetCatalogInfo(&fsref, kFSCatInfoNone, 0, 0, spec, 0);
|
---|
1650 | return ret;
|
---|
1651 | }
|
---|
1652 |
|
---|
1653 | Q_CORE_EXPORT void qt_mac_to_pascal_string(QString s, Str255 str, TextEncoding encoding=0, int len=-1)
|
---|
1654 | {
|
---|
1655 | if(len == -1)
|
---|
1656 | len = s.length();
|
---|
1657 | #if 0
|
---|
1658 | UnicodeMapping mapping;
|
---|
1659 | mapping.unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault,
|
---|
1660 | kTextEncodingDefaultVariant,
|
---|
1661 | kUnicode16BitFormat);
|
---|
1662 | mapping.otherEncoding = (encoding ? encoding : );
|
---|
1663 | mapping.mappingVersion = kUnicodeUseLatestMapping;
|
---|
1664 |
|
---|
1665 | UnicodeToTextInfo info;
|
---|
1666 | OSStatus err = CreateUnicodeToTextInfo(&mapping, &info);
|
---|
1667 | if(err != noErr) {
|
---|
1668 | qDebug("Qt: internal: Unable to create pascal string '%s'::%d [%ld]",
|
---|
1669 | s.left(len).latin1(), (int)encoding, err);
|
---|
1670 | return;
|
---|
1671 | }
|
---|
1672 | const int unilen = len * 2;
|
---|
1673 | const UniChar *unibuf = (UniChar *)s.unicode();
|
---|
1674 | ConvertFromUnicodeToPString(info, unilen, unibuf, str);
|
---|
1675 | DisposeUnicodeToTextInfo(&info);
|
---|
1676 | #else
|
---|
1677 | Q_UNUSED(encoding);
|
---|
1678 | CFStringGetPascalString(QCFString(s), str, 256, CFStringGetSystemEncoding());
|
---|
1679 | #endif
|
---|
1680 | }
|
---|
1681 |
|
---|
1682 | Q_CORE_EXPORT QString qt_mac_from_pascal_string(const Str255 pstr) {
|
---|
1683 | return QCFString(CFStringCreateWithPascalString(0, pstr, CFStringGetSystemEncoding()));
|
---|
1684 | }
|
---|
1685 |
|
---|
1686 |
|
---|
1687 |
|
---|
1688 | static QSysInfo::MacVersion macVersion()
|
---|
1689 | {
|
---|
1690 | SInt32 gestalt_version;
|
---|
1691 | if (Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) {
|
---|
1692 | return QSysInfo::MacVersion(((gestalt_version & 0x00F0) >> 4) + 2);
|
---|
1693 | }
|
---|
1694 | return QSysInfo::MV_Unknown;
|
---|
1695 | }
|
---|
1696 | const QSysInfo::MacVersion QSysInfo::MacintoshVersion = macVersion();
|
---|
1697 |
|
---|
1698 | #elif defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN) || defined(Q_OS_WINCE)
|
---|
1699 |
|
---|
1700 | QT_BEGIN_INCLUDE_NAMESPACE
|
---|
1701 | #include "qt_windows.h"
|
---|
1702 | QT_END_INCLUDE_NAMESPACE
|
---|
1703 |
|
---|
1704 | QSysInfo::WinVersion QSysInfo::windowsVersion()
|
---|
1705 | {
|
---|
1706 | #ifndef VER_PLATFORM_WIN32s
|
---|
1707 | #define VER_PLATFORM_WIN32s 0
|
---|
1708 | #endif
|
---|
1709 | #ifndef VER_PLATFORM_WIN32_WINDOWS
|
---|
1710 | #define VER_PLATFORM_WIN32_WINDOWS 1
|
---|
1711 | #endif
|
---|
1712 | #ifndef VER_PLATFORM_WIN32_NT
|
---|
1713 | #define VER_PLATFORM_WIN32_NT 2
|
---|
1714 | #endif
|
---|
1715 | #ifndef VER_PLATFORM_WIN32_CE
|
---|
1716 | #define VER_PLATFORM_WIN32_CE 3
|
---|
1717 | #endif
|
---|
1718 |
|
---|
1719 | static QSysInfo::WinVersion winver;
|
---|
1720 | if (winver)
|
---|
1721 | return winver;
|
---|
1722 | winver = QSysInfo::WV_NT;
|
---|
1723 | OSVERSIONINFOW osver;
|
---|
1724 | osver.dwOSVersionInfoSize = sizeof(osver);
|
---|
1725 | GetVersionEx(&osver);
|
---|
1726 | #ifdef Q_OS_WINCE
|
---|
1727 | DWORD qt_cever = 0;
|
---|
1728 | qt_cever = osver.dwMajorVersion * 100;
|
---|
1729 | qt_cever += osver.dwMinorVersion * 10;
|
---|
1730 | #endif
|
---|
1731 | switch (osver.dwPlatformId) {
|
---|
1732 | case VER_PLATFORM_WIN32s:
|
---|
1733 | winver = QSysInfo::WV_32s;
|
---|
1734 | break;
|
---|
1735 | case VER_PLATFORM_WIN32_WINDOWS:
|
---|
1736 | // We treat Windows Me (minor 90) the same as Windows 98
|
---|
1737 | if (osver.dwMinorVersion == 90)
|
---|
1738 | winver = QSysInfo::WV_Me;
|
---|
1739 | else if (osver.dwMinorVersion == 10)
|
---|
1740 | winver = QSysInfo::WV_98;
|
---|
1741 | else
|
---|
1742 | winver = QSysInfo::WV_95;
|
---|
1743 | break;
|
---|
1744 | #ifdef Q_OS_WINCE
|
---|
1745 | case VER_PLATFORM_WIN32_CE:
|
---|
1746 | if (qt_cever >= 600)
|
---|
1747 | winver = QSysInfo::WV_CE_6;
|
---|
1748 | if (qt_cever >= 500)
|
---|
1749 | winver = QSysInfo::WV_CE_5;
|
---|
1750 | else if (qt_cever >= 400)
|
---|
1751 | winver = QSysInfo::WV_CENET;
|
---|
1752 | else
|
---|
1753 | winver = QSysInfo::WV_CE;
|
---|
1754 | break;
|
---|
1755 | #endif
|
---|
1756 | default: // VER_PLATFORM_WIN32_NT
|
---|
1757 | if (osver.dwMajorVersion < 5) {
|
---|
1758 | winver = QSysInfo::WV_NT;
|
---|
1759 | } else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 0) {
|
---|
1760 | winver = QSysInfo::WV_2000;
|
---|
1761 | } else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 1) {
|
---|
1762 | winver = QSysInfo::WV_XP;
|
---|
1763 | } else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 2) {
|
---|
1764 | winver = QSysInfo::WV_2003;
|
---|
1765 | } else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 0) {
|
---|
1766 | winver = QSysInfo::WV_VISTA;
|
---|
1767 | } else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 1) {
|
---|
1768 | winver = QSysInfo::WV_WINDOWS7;
|
---|
1769 | } else {
|
---|
1770 | qWarning("Qt: Untested Windows version %d.%d detected!",
|
---|
1771 | int(osver.dwMajorVersion), int(osver.dwMinorVersion));
|
---|
1772 | winver = QSysInfo::WV_NT_based;
|
---|
1773 | }
|
---|
1774 | }
|
---|
1775 |
|
---|
1776 | #ifdef QT_DEBUG
|
---|
1777 | {
|
---|
1778 | QByteArray override = qgetenv("QT_WINVER_OVERRIDE");
|
---|
1779 | if (override.isEmpty())
|
---|
1780 | return winver;
|
---|
1781 |
|
---|
1782 | if (override == "Me")
|
---|
1783 | winver = QSysInfo::WV_Me;
|
---|
1784 | if (override == "95")
|
---|
1785 | winver = QSysInfo::WV_95;
|
---|
1786 | else if (override == "98")
|
---|
1787 | winver = QSysInfo::WV_98;
|
---|
1788 | else if (override == "NT")
|
---|
1789 | winver = QSysInfo::WV_NT;
|
---|
1790 | else if (override == "2000")
|
---|
1791 | winver = QSysInfo::WV_2000;
|
---|
1792 | else if (override == "2003")
|
---|
1793 | winver = QSysInfo::WV_2003;
|
---|
1794 | else if (override == "XP")
|
---|
1795 | winver = QSysInfo::WV_XP;
|
---|
1796 | else if (override == "VISTA")
|
---|
1797 | winver = QSysInfo::WV_VISTA;
|
---|
1798 | else if (override == "WINDOWS7")
|
---|
1799 | winver = QSysInfo::WV_WINDOWS7;
|
---|
1800 | }
|
---|
1801 | #endif
|
---|
1802 |
|
---|
1803 | return winver;
|
---|
1804 | }
|
---|
1805 |
|
---|
1806 | const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion();
|
---|
1807 |
|
---|
1808 | #endif
|
---|
1809 |
|
---|
1810 | #ifdef Q_OS_SYMBIAN
|
---|
1811 | # ifdef Q_WS_S60
|
---|
1812 | static QSysInfo::S60Version cachedS60Version = QSysInfo::S60Version(-1);
|
---|
1813 |
|
---|
1814 | QSysInfo::S60Version QSysInfo::s60Version()
|
---|
1815 | {
|
---|
1816 | if (cachedS60Version != -1)
|
---|
1817 | return cachedS60Version;
|
---|
1818 |
|
---|
1819 | // Use pure Symbian code, because if done using QDir, there will be a call back
|
---|
1820 | // to this method, resulting doing this expensive operation twice before the cache kicks in.
|
---|
1821 | // Pure Symbian code also makes this method ~10x faster, speeding up the application launch.
|
---|
1822 | RFs rfs = qt_s60GetRFs();
|
---|
1823 | TFindFile fileFinder(rfs);
|
---|
1824 | CDir* contents;
|
---|
1825 | TInt err = fileFinder.FindWildByDir(qt_S60Filter, qt_S60SystemInstallDir, contents);
|
---|
1826 | if (err == KErrNone) {
|
---|
1827 | err = contents->Sort(EDescending|ESortByName);
|
---|
1828 | if (err == KErrNone && contents->Count() > 0 && (*contents)[0].iName.Length() >= 12) {
|
---|
1829 | TInt major = (*contents)[0].iName[9] - '0';
|
---|
1830 | TInt minor = (*contents)[0].iName[11] - '0';
|
---|
1831 | if (major == 3) {
|
---|
1832 | if (minor == 1) {
|
---|
1833 | return cachedS60Version = SV_S60_3_1;
|
---|
1834 | } else if (minor == 2) {
|
---|
1835 | return cachedS60Version = SV_S60_3_2;
|
---|
1836 | }
|
---|
1837 | } else if (major == 5) {
|
---|
1838 | if (minor == 0) {
|
---|
1839 | return cachedS60Version = SV_S60_5_0;
|
---|
1840 | }
|
---|
1841 | else if (minor == 1) {
|
---|
1842 | return cachedS60Version = SV_S60_5_1;
|
---|
1843 | }
|
---|
1844 | else if (minor == 2) {
|
---|
1845 | return cachedS60Version = SV_S60_5_2;
|
---|
1846 | }
|
---|
1847 | }
|
---|
1848 | }
|
---|
1849 | delete contents;
|
---|
1850 | }
|
---|
1851 |
|
---|
1852 | # ifdef Q_CC_NOKIAX86
|
---|
1853 | // Some emulator environments may not contain the version specific .sis files, so
|
---|
1854 | // simply hardcode the version on those environments.
|
---|
1855 | # if defined(__SERIES60_31__)
|
---|
1856 | return cachedS60Version = SV_S60_3_1;
|
---|
1857 | # elif defined(__S60_32__)
|
---|
1858 | return cachedS60Version = SV_S60_3_2;
|
---|
1859 | # elif defined(__S60_50__)
|
---|
1860 | return cachedS60Version = SV_S60_5_0;
|
---|
1861 | # endif
|
---|
1862 | # endif
|
---|
1863 | //If reaching here, it was not possible to determine the version
|
---|
1864 | return cachedS60Version = SV_S60_Unknown;
|
---|
1865 | }
|
---|
1866 | QSysInfo::SymbianVersion QSysInfo::symbianVersion()
|
---|
1867 | {
|
---|
1868 | switch (s60Version()) {
|
---|
1869 | case SV_S60_3_1:
|
---|
1870 | return SV_9_2;
|
---|
1871 | case SV_S60_3_2:
|
---|
1872 | return SV_9_3;
|
---|
1873 | case SV_S60_5_0:
|
---|
1874 | return SV_9_4;
|
---|
1875 | case SV_S60_5_1:
|
---|
1876 | return SV_9_4;
|
---|
1877 | case SV_S60_5_2:
|
---|
1878 | return SV_9_4;
|
---|
1879 | default:
|
---|
1880 | return SV_Unknown;
|
---|
1881 | }
|
---|
1882 | }
|
---|
1883 | #else
|
---|
1884 | QSysInfo::S60Version QSysInfo::s60Version()
|
---|
1885 | {
|
---|
1886 | return SV_S60_None;
|
---|
1887 | }
|
---|
1888 |
|
---|
1889 | QSysInfo::SymbianVersion QSysInfo::symbianVersion()
|
---|
1890 | {
|
---|
1891 | return SV_Unknown;
|
---|
1892 | }
|
---|
1893 | # endif // ifdef Q_WS_S60
|
---|
1894 | #endif // ifdef Q_OS_SYMBIAN
|
---|
1895 |
|
---|
1896 | /*!
|
---|
1897 | \macro void Q_ASSERT(bool test)
|
---|
1898 | \relates <QtGlobal>
|
---|
1899 |
|
---|
1900 | Prints a warning message containing the source code file name and
|
---|
1901 | line number if \a test is false.
|
---|
1902 |
|
---|
1903 | Q_ASSERT() is useful for testing pre- and post-conditions
|
---|
1904 | during development. It does nothing if \c QT_NO_DEBUG was defined
|
---|
1905 | during compilation.
|
---|
1906 |
|
---|
1907 | Example:
|
---|
1908 |
|
---|
1909 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 17
|
---|
1910 |
|
---|
1911 | If \c b is zero, the Q_ASSERT statement will output the following
|
---|
1912 | message using the qFatal() function:
|
---|
1913 |
|
---|
1914 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 18
|
---|
1915 |
|
---|
1916 | \sa Q_ASSERT_X(), qFatal(), {Debugging Techniques}
|
---|
1917 | */
|
---|
1918 |
|
---|
1919 | /*!
|
---|
1920 | \macro void Q_ASSERT_X(bool test, const char *where, const char *what)
|
---|
1921 | \relates <QtGlobal>
|
---|
1922 |
|
---|
1923 | Prints the message \a what together with the location \a where,
|
---|
1924 | the source file name and line number if \a test is false.
|
---|
1925 |
|
---|
1926 | Q_ASSERT_X is useful for testing pre- and post-conditions during
|
---|
1927 | development. It does nothing if \c QT_NO_DEBUG was defined during
|
---|
1928 | compilation.
|
---|
1929 |
|
---|
1930 | Example:
|
---|
1931 |
|
---|
1932 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 19
|
---|
1933 |
|
---|
1934 | If \c b is zero, the Q_ASSERT_X statement will output the following
|
---|
1935 | message using the qFatal() function:
|
---|
1936 |
|
---|
1937 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 20
|
---|
1938 |
|
---|
1939 | \sa Q_ASSERT(), qFatal(), {Debugging Techniques}
|
---|
1940 | */
|
---|
1941 |
|
---|
1942 | /*!
|
---|
1943 | \macro void Q_CHECK_PTR(void *pointer)
|
---|
1944 | \relates <QtGlobal>
|
---|
1945 |
|
---|
1946 | If \a pointer is 0, prints a warning message containing the source
|
---|
1947 | code's file name and line number, saying that the program ran out
|
---|
1948 | of memory.
|
---|
1949 |
|
---|
1950 | Q_CHECK_PTR does nothing if \c QT_NO_DEBUG was defined during
|
---|
1951 | compilation.
|
---|
1952 |
|
---|
1953 | Example:
|
---|
1954 |
|
---|
1955 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 21
|
---|
1956 |
|
---|
1957 | \sa qWarning(), {Debugging Techniques}
|
---|
1958 | */
|
---|
1959 |
|
---|
1960 | /*!
|
---|
1961 | \fn T *q_check_ptr(T *pointer)
|
---|
1962 | \relates <QtGlobal>
|
---|
1963 |
|
---|
1964 | Users Q_CHECK_PTR on \a pointer, then returns \a pointer.
|
---|
1965 |
|
---|
1966 | This can be used as an inline version of Q_CHECK_PTR.
|
---|
1967 | */
|
---|
1968 |
|
---|
1969 | /*!
|
---|
1970 | \macro const char* Q_FUNC_INFO()
|
---|
1971 | \relates <QtGlobal>
|
---|
1972 |
|
---|
1973 | Expands to a string that describe the function the macro resides in. How this string looks
|
---|
1974 | more specifically is compiler dependent. With GNU GCC it is typically the function signature,
|
---|
1975 | while with other compilers it might be the line and column number.
|
---|
1976 |
|
---|
1977 | Q_FUNC_INFO can be conveniently used with qDebug(). For example, this function:
|
---|
1978 |
|
---|
1979 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 22
|
---|
1980 |
|
---|
1981 | when instantiated with the integer type, will with the GCC compiler produce:
|
---|
1982 |
|
---|
1983 | \tt{const TInputType& myMin(const TInputType&, const TInputType&) [with TInputType = int] was called with value1: 3 value2: 4}
|
---|
1984 |
|
---|
1985 | If this macro is used outside a function, the behavior is undefined.
|
---|
1986 | */
|
---|
1987 |
|
---|
1988 | /*
|
---|
1989 | The Q_CHECK_PTR macro calls this function if an allocation check
|
---|
1990 | fails.
|
---|
1991 | */
|
---|
1992 | void qt_check_pointer(const char *n, int l)
|
---|
1993 | {
|
---|
1994 | qWarning("In file %s, line %d: Out of memory", n, l);
|
---|
1995 | }
|
---|
1996 |
|
---|
1997 | #ifndef QT_NO_EXCEPTIONS
|
---|
1998 | /* \internal
|
---|
1999 | Allows you to throw an exception without including <new>
|
---|
2000 | Called internally from Q_CHECK_PTR on certain OS combinations
|
---|
2001 | */
|
---|
2002 | void qBadAlloc()
|
---|
2003 | {
|
---|
2004 | QT_THROW(std::bad_alloc());
|
---|
2005 | }
|
---|
2006 | #endif
|
---|
2007 |
|
---|
2008 | /*
|
---|
2009 | The Q_ASSERT macro calls this function when the test fails.
|
---|
2010 | */
|
---|
2011 | void qt_assert(const char *assertion, const char *file, int line)
|
---|
2012 | {
|
---|
2013 | qFatal("ASSERT: \"%s\" in file %s, line %d", assertion, file, line);
|
---|
2014 | }
|
---|
2015 |
|
---|
2016 | /*
|
---|
2017 | The Q_ASSERT_X macro calls this function when the test fails.
|
---|
2018 | */
|
---|
2019 | void qt_assert_x(const char *where, const char *what, const char *file, int line)
|
---|
2020 | {
|
---|
2021 | qFatal("ASSERT failure in %s: \"%s\", file %s, line %d", where, what, file, line);
|
---|
2022 | }
|
---|
2023 |
|
---|
2024 |
|
---|
2025 | /*
|
---|
2026 | Dijkstra's bisection algorithm to find the square root of an integer.
|
---|
2027 | Deliberately not exported as part of the Qt API, but used in both
|
---|
2028 | qsimplerichtext.cpp and qgfxraster_qws.cpp
|
---|
2029 | */
|
---|
2030 | Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n)
|
---|
2031 | {
|
---|
2032 | // n must be in the range 0...UINT_MAX/2-1
|
---|
2033 | if (n >= (UINT_MAX>>2)) {
|
---|
2034 | unsigned int r = 2 * qt_int_sqrt(n / 4);
|
---|
2035 | unsigned int r2 = r + 1;
|
---|
2036 | return (n >= r2 * r2) ? r2 : r;
|
---|
2037 | }
|
---|
2038 | uint h, p= 0, q= 1, r= n;
|
---|
2039 | while (q <= n)
|
---|
2040 | q <<= 2;
|
---|
2041 | while (q != 1) {
|
---|
2042 | q >>= 2;
|
---|
2043 | h= p + q;
|
---|
2044 | p >>= 1;
|
---|
2045 | if (r >= h) {
|
---|
2046 | p += q;
|
---|
2047 | r -= h;
|
---|
2048 | }
|
---|
2049 | }
|
---|
2050 | return p;
|
---|
2051 | }
|
---|
2052 |
|
---|
2053 | #if defined(qMemCopy)
|
---|
2054 | # undef qMemCopy
|
---|
2055 | #endif
|
---|
2056 | #if defined(qMemSet)
|
---|
2057 | # undef qMemSet
|
---|
2058 | #endif
|
---|
2059 |
|
---|
2060 | void *qMemCopy(void *dest, const void *src, size_t n) { return memcpy(dest, src, n); }
|
---|
2061 | void *qMemSet(void *dest, int c, size_t n) { return memset(dest, c, n); }
|
---|
2062 |
|
---|
2063 | static QtMsgHandler handler = 0; // pointer to debug handler
|
---|
2064 |
|
---|
2065 | #if defined(Q_CC_MWERKS) && defined(Q_OS_MACX)
|
---|
2066 | extern bool qt_is_gui_used;
|
---|
2067 | static void mac_default_handler(const char *msg)
|
---|
2068 | {
|
---|
2069 | if (qt_is_gui_used) {
|
---|
2070 | Str255 pmsg;
|
---|
2071 | qt_mac_to_pascal_string(msg, pmsg);
|
---|
2072 | DebugStr(pmsg);
|
---|
2073 | } else {
|
---|
2074 | fprintf(stderr, msg);
|
---|
2075 | }
|
---|
2076 | }
|
---|
2077 | #endif // Q_CC_MWERKS && Q_OS_MACX
|
---|
2078 |
|
---|
2079 |
|
---|
2080 |
|
---|
2081 | QString qt_error_string(int errorCode)
|
---|
2082 | {
|
---|
2083 | const char *s = 0;
|
---|
2084 | QString ret;
|
---|
2085 | if (errorCode == -1) {
|
---|
2086 | #if defined(Q_OS_WIN)
|
---|
2087 | errorCode = GetLastError();
|
---|
2088 | #else
|
---|
2089 | errorCode = errno;
|
---|
2090 | #endif
|
---|
2091 | }
|
---|
2092 | switch (errorCode) {
|
---|
2093 | case 0:
|
---|
2094 | break;
|
---|
2095 | case EACCES:
|
---|
2096 | s = QT_TRANSLATE_NOOP("QIODevice", "Permission denied");
|
---|
2097 | break;
|
---|
2098 | case EMFILE:
|
---|
2099 | s = QT_TRANSLATE_NOOP("QIODevice", "Too many open files");
|
---|
2100 | break;
|
---|
2101 | case ENOENT:
|
---|
2102 | s = QT_TRANSLATE_NOOP("QIODevice", "No such file or directory");
|
---|
2103 | break;
|
---|
2104 | case ENOSPC:
|
---|
2105 | s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device");
|
---|
2106 | break;
|
---|
2107 | default: {
|
---|
2108 | #ifdef Q_OS_WIN
|
---|
2109 | wchar_t *string = 0;
|
---|
2110 | FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
|
---|
2111 | NULL,
|
---|
2112 | errorCode,
|
---|
2113 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
---|
2114 | (LPWSTR)&string,
|
---|
2115 | 0,
|
---|
2116 | NULL);
|
---|
2117 | ret = QString::fromWCharArray(string);
|
---|
2118 | LocalFree((HLOCAL)string);
|
---|
2119 |
|
---|
2120 | if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND)
|
---|
2121 | ret = QString::fromLatin1("The specified module could not be found.");
|
---|
2122 |
|
---|
2123 | #elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX)
|
---|
2124 |
|
---|
2125 | QByteArray buf(1024, '\0');
|
---|
2126 | strerror_r(errorCode, buf.data(), buf.size());
|
---|
2127 | ret = QString::fromLocal8Bit(buf.constData());
|
---|
2128 | #else
|
---|
2129 | ret = QString::fromLocal8Bit(strerror(errorCode));
|
---|
2130 | #endif
|
---|
2131 | break; }
|
---|
2132 | }
|
---|
2133 | if (s)
|
---|
2134 | // ######## this breaks moc build currently
|
---|
2135 | // ret = QCoreApplication::translate("QIODevice", s);
|
---|
2136 | ret = QString::fromLatin1(s);
|
---|
2137 | return ret.trimmed();
|
---|
2138 | }
|
---|
2139 |
|
---|
2140 |
|
---|
2141 | /*!
|
---|
2142 | \fn QtMsgHandler qInstallMsgHandler(QtMsgHandler handler)
|
---|
2143 | \relates <QtGlobal>
|
---|
2144 |
|
---|
2145 | Installs a Qt message \a handler which has been defined
|
---|
2146 | previously. Returns a pointer to the previous message handler
|
---|
2147 | (which may be 0).
|
---|
2148 |
|
---|
2149 | The message handler is a function that prints out debug messages,
|
---|
2150 | warnings, critical and fatal error messages. The Qt library (debug
|
---|
2151 | mode) contains hundreds of warning messages that are printed
|
---|
2152 | when internal errors (usually invalid function arguments)
|
---|
2153 | occur. Qt built in release mode also contains such warnings unless
|
---|
2154 | QT_NO_WARNING_OUTPUT and/or QT_NO_DEBUG_OUTPUT have been set during
|
---|
2155 | compilation. If you implement your own message handler, you get total
|
---|
2156 | control of these messages.
|
---|
2157 |
|
---|
2158 | The default message handler prints the message to the standard
|
---|
2159 | output under X11 or to the debugger under Windows. If it is a
|
---|
2160 | fatal message, the application aborts immediately.
|
---|
2161 |
|
---|
2162 | Only one message handler can be defined, since this is usually
|
---|
2163 | done on an application-wide basis to control debug output.
|
---|
2164 |
|
---|
2165 | To restore the message handler, call \c qInstallMsgHandler(0).
|
---|
2166 |
|
---|
2167 | Example:
|
---|
2168 |
|
---|
2169 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 23
|
---|
2170 |
|
---|
2171 | \sa qDebug(), qWarning(), qCritical(), qFatal(), QtMsgType,
|
---|
2172 | {Debugging Techniques}
|
---|
2173 | */
|
---|
2174 | #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB)
|
---|
2175 | extern bool usingWinMain;
|
---|
2176 | extern Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char* str);
|
---|
2177 | #endif
|
---|
2178 |
|
---|
2179 | QtMsgHandler qInstallMsgHandler(QtMsgHandler h)
|
---|
2180 | {
|
---|
2181 | QtMsgHandler old = handler;
|
---|
2182 | handler = h;
|
---|
2183 | #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB)
|
---|
2184 | if (!handler && usingWinMain)
|
---|
2185 | handler = qWinMsgHandler;
|
---|
2186 | #endif
|
---|
2187 | return old;
|
---|
2188 | }
|
---|
2189 |
|
---|
2190 | /*!
|
---|
2191 | \internal
|
---|
2192 | */
|
---|
2193 | void qt_message_output(QtMsgType msgType, const char *buf)
|
---|
2194 | {
|
---|
2195 | if (handler) {
|
---|
2196 | (*handler)(msgType, buf);
|
---|
2197 | } else {
|
---|
2198 | #if defined(Q_CC_MWERKS) && defined(Q_OS_MACX)
|
---|
2199 | mac_default_handler(buf);
|
---|
2200 | #elif defined(Q_OS_WINCE)
|
---|
2201 | QString fstr = QString::fromLatin1(buf);
|
---|
2202 | fstr += QLatin1Char('\n');
|
---|
2203 | OutputDebugString(reinterpret_cast<const wchar_t *> (fstr.utf16()));
|
---|
2204 | #elif defined(Q_OS_SYMBIAN)
|
---|
2205 | // RDebug::Print has a cap of 256 characters so break it up
|
---|
2206 | _LIT(format, "[Qt Message] %S");
|
---|
2207 | const int maxBlockSize = 256 - ((const TDesC &)format).Length();
|
---|
2208 | const TPtrC8 ptr(reinterpret_cast<const TUint8*>(buf));
|
---|
2209 | HBufC* hbuffer = q_check_ptr(HBufC::New(qMin(maxBlockSize, ptr.Length())));
|
---|
2210 | for (int i = 0; i < ptr.Length(); i += hbuffer->Length()) {
|
---|
2211 | hbuffer->Des().Copy(ptr.Mid(i, qMin(maxBlockSize, ptr.Length()-i)));
|
---|
2212 | RDebug::Print(format, hbuffer);
|
---|
2213 | }
|
---|
2214 | delete hbuffer;
|
---|
2215 | #else
|
---|
2216 | fprintf(stderr, "%s\n", buf);
|
---|
2217 | fflush(stderr);
|
---|
2218 | #endif
|
---|
2219 | }
|
---|
2220 |
|
---|
2221 | if (msgType == QtFatalMsg
|
---|
2222 | || (msgType == QtWarningMsg
|
---|
2223 | && (!qgetenv("QT_FATAL_WARNINGS").isNull())) ) {
|
---|
2224 |
|
---|
2225 | #if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR)
|
---|
2226 | // get the current report mode
|
---|
2227 | int reportMode = _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW);
|
---|
2228 | _CrtSetReportMode(_CRT_ERROR, reportMode);
|
---|
2229 | #if !defined(Q_OS_WINCE)
|
---|
2230 | int ret = _CrtDbgReport(_CRT_ERROR, __FILE__, __LINE__, QT_VERSION_STR, buf);
|
---|
2231 | #else
|
---|
2232 | int ret = _CrtDbgReportW(_CRT_ERROR, _CRT_WIDE(__FILE__),
|
---|
2233 | __LINE__, _CRT_WIDE(QT_VERSION_STR), reinterpret_cast<const wchar_t *> (QString::fromLatin1(buf).utf16()));
|
---|
2234 | #endif
|
---|
2235 | if (ret == 0 && reportMode & _CRTDBG_MODE_WNDW)
|
---|
2236 | return; // ignore
|
---|
2237 | else if (ret == 1)
|
---|
2238 | _CrtDbgBreak();
|
---|
2239 | #endif
|
---|
2240 |
|
---|
2241 | #if defined(Q_OS_SYMBIAN)
|
---|
2242 | __DEBUGGER(); // on the emulator, get the debugger to kick in if there's one around
|
---|
2243 | TBuf<256> tmp;
|
---|
2244 | TPtrC8 ptr(reinterpret_cast<const TUint8*>(buf));
|
---|
2245 | TInt len = Min(tmp.MaxLength(), ptr.Length());
|
---|
2246 | tmp.Copy(ptr.Left(len));
|
---|
2247 | // Panic the current thread. We don't use real panic codes, so 0 has no special meaning.
|
---|
2248 | User::Panic(tmp, 0);
|
---|
2249 | #elif (defined(Q_OS_UNIX) || defined(Q_CC_MINGW))
|
---|
2250 | abort(); // trap; generates core dump
|
---|
2251 | #else
|
---|
2252 | exit(1); // goodbye cruel world
|
---|
2253 | #endif
|
---|
2254 | }
|
---|
2255 | }
|
---|
2256 |
|
---|
2257 | #if !defined(QT_NO_EXCEPTIONS)
|
---|
2258 | /*!
|
---|
2259 | \internal
|
---|
2260 | Uses a local buffer to output the message. Not locale safe + cuts off
|
---|
2261 | everything after character 255, but will work in out of memory situations.
|
---|
2262 | */
|
---|
2263 | static void qEmergencyOut(QtMsgType msgType, const char *msg, va_list ap)
|
---|
2264 | {
|
---|
2265 | char emergency_buf[256] = { '\0' };
|
---|
2266 | emergency_buf[255] = '\0';
|
---|
2267 | if (msg)
|
---|
2268 | qvsnprintf(emergency_buf, 255, msg, ap);
|
---|
2269 | qt_message_output(msgType, emergency_buf);
|
---|
2270 | }
|
---|
2271 | #endif
|
---|
2272 |
|
---|
2273 | /*!
|
---|
2274 | \internal
|
---|
2275 | */
|
---|
2276 | static void qt_message(QtMsgType msgType, const char *msg, va_list ap)
|
---|
2277 | {
|
---|
2278 | #if !defined(QT_NO_EXCEPTIONS)
|
---|
2279 | if (std::uncaught_exception()) {
|
---|
2280 | qEmergencyOut(msgType, msg, ap);
|
---|
2281 | return;
|
---|
2282 | }
|
---|
2283 | #endif
|
---|
2284 | QByteArray buf;
|
---|
2285 | if (msg) {
|
---|
2286 | QT_TRY {
|
---|
2287 | buf = QString().vsprintf(msg, ap).toLocal8Bit();
|
---|
2288 | } QT_CATCH(const std::bad_alloc &) {
|
---|
2289 | #if !defined(QT_NO_EXCEPTIONS)
|
---|
2290 | qEmergencyOut(msgType, msg, ap);
|
---|
2291 | // don't rethrow - we use qWarning and friends in destructors.
|
---|
2292 | return;
|
---|
2293 | #endif
|
---|
2294 | }
|
---|
2295 | }
|
---|
2296 | qt_message_output(msgType, buf.constData());
|
---|
2297 | }
|
---|
2298 |
|
---|
2299 | #undef qDebug
|
---|
2300 | /*!
|
---|
2301 | \relates <QtGlobal>
|
---|
2302 |
|
---|
2303 | Calls the message handler with the debug message \a msg. If no
|
---|
2304 | message handler has been installed, the message is printed to
|
---|
2305 | stderr. Under Windows, the message is sent to the console, if it is a
|
---|
2306 | console application; otherwise, it is sent to the debugger. This
|
---|
2307 | function does nothing if \c QT_NO_DEBUG_OUTPUT was defined
|
---|
2308 | during compilation.
|
---|
2309 |
|
---|
2310 | If you pass the function a format string and a list of arguments,
|
---|
2311 | it works in similar way to the C printf() function. The format
|
---|
2312 | should be a Latin-1 string.
|
---|
2313 |
|
---|
2314 | Example:
|
---|
2315 |
|
---|
2316 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 24
|
---|
2317 |
|
---|
2318 | If you include \c <QtDebug>, a more convenient syntax is also
|
---|
2319 | available:
|
---|
2320 |
|
---|
2321 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 25
|
---|
2322 |
|
---|
2323 | With this syntax, the function returns a QDebug object that is
|
---|
2324 | configured to use the QtDebugMsg message type. It automatically
|
---|
2325 | puts a single space between each item, and outputs a newline at
|
---|
2326 | the end. It supports many C++ and Qt types.
|
---|
2327 |
|
---|
2328 | To suppress the output at run-time, install your own message handler
|
---|
2329 | with qInstallMsgHandler().
|
---|
2330 |
|
---|
2331 | \sa qWarning(), qCritical(), qFatal(), qInstallMsgHandler(),
|
---|
2332 | {Debugging Techniques}
|
---|
2333 | */
|
---|
2334 | void qDebug(const char *msg, ...)
|
---|
2335 | {
|
---|
2336 | va_list ap;
|
---|
2337 | va_start(ap, msg); // use variable arg list
|
---|
2338 | qt_message(QtDebugMsg, msg, ap);
|
---|
2339 | va_end(ap);
|
---|
2340 | }
|
---|
2341 |
|
---|
2342 | #undef qWarning
|
---|
2343 | /*!
|
---|
2344 | \relates <QtGlobal>
|
---|
2345 |
|
---|
2346 | Calls the message handler with the warning message \a msg. If no
|
---|
2347 | message handler has been installed, the message is printed to
|
---|
2348 | stderr. Under Windows, the message is sent to the debugger. This
|
---|
2349 | function does nothing if \c QT_NO_WARNING_OUTPUT was defined
|
---|
2350 | during compilation; it exits if the environment variable \c
|
---|
2351 | QT_FATAL_WARNINGS is defined.
|
---|
2352 |
|
---|
2353 | This function takes a format string and a list of arguments,
|
---|
2354 | similar to the C printf() function. The format should be a Latin-1
|
---|
2355 | string.
|
---|
2356 |
|
---|
2357 | Example:
|
---|
2358 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 26
|
---|
2359 |
|
---|
2360 | If you include <QtDebug>, a more convenient syntax is
|
---|
2361 | also available:
|
---|
2362 |
|
---|
2363 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 27
|
---|
2364 |
|
---|
2365 | This syntax inserts a space between each item, and
|
---|
2366 | appends a newline at the end.
|
---|
2367 |
|
---|
2368 | To supress the output at runtime, install your own message handler
|
---|
2369 | with qInstallMsgHandler().
|
---|
2370 |
|
---|
2371 | \sa qDebug(), qCritical(), qFatal(), qInstallMsgHandler(),
|
---|
2372 | {Debugging Techniques}
|
---|
2373 | */
|
---|
2374 | void qWarning(const char *msg, ...)
|
---|
2375 | {
|
---|
2376 | va_list ap;
|
---|
2377 | va_start(ap, msg); // use variable arg list
|
---|
2378 | qt_message(QtWarningMsg, msg, ap);
|
---|
2379 | va_end(ap);
|
---|
2380 | }
|
---|
2381 |
|
---|
2382 | /*!
|
---|
2383 | \relates <QtGlobal>
|
---|
2384 |
|
---|
2385 | Calls the message handler with the critical message \a msg. If no
|
---|
2386 | message handler has been installed, the message is printed to
|
---|
2387 | stderr. Under Windows, the message is sent to the debugger.
|
---|
2388 |
|
---|
2389 | This function takes a format string and a list of arguments,
|
---|
2390 | similar to the C printf() function. The format should be a Latin-1
|
---|
2391 | string.
|
---|
2392 |
|
---|
2393 | Example:
|
---|
2394 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 28
|
---|
2395 |
|
---|
2396 | If you include <QtDebug>, a more convenient syntax is
|
---|
2397 | also available:
|
---|
2398 |
|
---|
2399 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 29
|
---|
2400 |
|
---|
2401 | A space is inserted between the items, and a newline is
|
---|
2402 | appended at the end.
|
---|
2403 |
|
---|
2404 | To supress the output at runtime, install your own message handler
|
---|
2405 | with qInstallMsgHandler().
|
---|
2406 |
|
---|
2407 | \sa qDebug(), qWarning(), qFatal(), qInstallMsgHandler(),
|
---|
2408 | {Debugging Techniques}
|
---|
2409 | */
|
---|
2410 | void qCritical(const char *msg, ...)
|
---|
2411 | {
|
---|
2412 | va_list ap;
|
---|
2413 | va_start(ap, msg); // use variable arg list
|
---|
2414 | qt_message(QtCriticalMsg, msg, ap);
|
---|
2415 | va_end(ap);
|
---|
2416 | }
|
---|
2417 |
|
---|
2418 | #ifdef QT3_SUPPORT
|
---|
2419 | void qSystemWarning(const char *msg, int code)
|
---|
2420 | { qCritical("%s (%s)", msg, qt_error_string(code).toLocal8Bit().constData()); }
|
---|
2421 | #endif // QT3_SUPPORT
|
---|
2422 |
|
---|
2423 | void qErrnoWarning(const char *msg, ...)
|
---|
2424 | {
|
---|
2425 | // qt_error_string() will allocate anyway, so we don't have
|
---|
2426 | // to be careful here (like we do in plain qWarning())
|
---|
2427 | QString buf;
|
---|
2428 | va_list ap;
|
---|
2429 | va_start(ap, msg);
|
---|
2430 | if (msg)
|
---|
2431 | buf.vsprintf(msg, ap);
|
---|
2432 | va_end(ap);
|
---|
2433 |
|
---|
2434 | qCritical("%s (%s)", buf.toLocal8Bit().constData(), qt_error_string(-1).toLocal8Bit().constData());
|
---|
2435 | }
|
---|
2436 |
|
---|
2437 | void qErrnoWarning(int code, const char *msg, ...)
|
---|
2438 | {
|
---|
2439 | // qt_error_string() will allocate anyway, so we don't have
|
---|
2440 | // to be careful here (like we do in plain qWarning())
|
---|
2441 | QString buf;
|
---|
2442 | va_list ap;
|
---|
2443 | va_start(ap, msg);
|
---|
2444 | if (msg)
|
---|
2445 | buf.vsprintf(msg, ap);
|
---|
2446 | va_end(ap);
|
---|
2447 |
|
---|
2448 | qCritical("%s (%s)", buf.toLocal8Bit().constData(), qt_error_string(code).toLocal8Bit().constData());
|
---|
2449 | }
|
---|
2450 |
|
---|
2451 | /*!
|
---|
2452 | \relates <QtGlobal>
|
---|
2453 |
|
---|
2454 | Calls the message handler with the fatal message \a msg. If no
|
---|
2455 | message handler has been installed, the message is printed to
|
---|
2456 | stderr. Under Windows, the message is sent to the debugger.
|
---|
2457 |
|
---|
2458 | If you are using the \bold{default message handler} this function will
|
---|
2459 | abort on Unix systems to create a core dump. On Windows, for debug builds,
|
---|
2460 | this function will report a _CRT_ERROR enabling you to connect a debugger
|
---|
2461 | to the application.
|
---|
2462 |
|
---|
2463 | This function takes a format string and a list of arguments,
|
---|
2464 | similar to the C printf() function.
|
---|
2465 |
|
---|
2466 | Example:
|
---|
2467 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 30
|
---|
2468 |
|
---|
2469 | To supress the output at runtime, install your own message handler
|
---|
2470 | with qInstallMsgHandler().
|
---|
2471 |
|
---|
2472 | \sa qDebug(), qCritical(), qWarning(), qInstallMsgHandler(),
|
---|
2473 | {Debugging Techniques}
|
---|
2474 | */
|
---|
2475 | void qFatal(const char *msg, ...)
|
---|
2476 | {
|
---|
2477 | va_list ap;
|
---|
2478 | va_start(ap, msg); // use variable arg list
|
---|
2479 | qt_message(QtFatalMsg, msg, ap);
|
---|
2480 | va_end(ap);
|
---|
2481 | }
|
---|
2482 |
|
---|
2483 | // getenv is declared as deprecated in VS2005. This function
|
---|
2484 | // makes use of the new secure getenv function.
|
---|
2485 | QByteArray qgetenv(const char *varName)
|
---|
2486 | {
|
---|
2487 | #if defined(_MSC_VER) && _MSC_VER >= 1400
|
---|
2488 | size_t requiredSize = 0;
|
---|
2489 | QByteArray buffer;
|
---|
2490 | getenv_s(&requiredSize, 0, 0, varName);
|
---|
2491 | if (requiredSize == 0)
|
---|
2492 | return buffer;
|
---|
2493 | buffer.resize(int(requiredSize));
|
---|
2494 | getenv_s(&requiredSize, buffer.data(), requiredSize, varName);
|
---|
2495 | // requiredSize includes the terminating null, which we don't want.
|
---|
2496 | Q_ASSERT(buffer.endsWith('\0'));
|
---|
2497 | buffer.chop(1);
|
---|
2498 | return buffer;
|
---|
2499 | #else
|
---|
2500 | return QByteArray(::getenv(varName));
|
---|
2501 | #endif
|
---|
2502 | }
|
---|
2503 |
|
---|
2504 | bool qputenv(const char *varName, const QByteArray& value)
|
---|
2505 | {
|
---|
2506 | #if defined(_MSC_VER) && _MSC_VER >= 1400
|
---|
2507 | return _putenv_s(varName, value.constData()) == 0;
|
---|
2508 | #else
|
---|
2509 | QByteArray buffer(varName);
|
---|
2510 | buffer += '=';
|
---|
2511 | buffer += value;
|
---|
2512 | char* envVar = qstrdup(buffer.constData());
|
---|
2513 | int result = putenv(envVar);
|
---|
2514 | if (result != 0) // error. we have to delete the string.
|
---|
2515 | delete[] envVar;
|
---|
2516 | return result == 0;
|
---|
2517 | #endif
|
---|
2518 | }
|
---|
2519 |
|
---|
2520 | #if (defined(Q_OS_UNIX) || defined(Q_OS_WIN)) && !defined(QT_NO_THREAD)
|
---|
2521 |
|
---|
2522 | # if defined(Q_OS_INTEGRITY) && defined(__GHS_VERSION_NUMBER) && (__GHS_VERSION_NUMBER < 500)
|
---|
2523 | // older versions of INTEGRITY used a long instead of a uint for the seed.
|
---|
2524 | typedef long SeedStorageType;
|
---|
2525 | # else
|
---|
2526 | typedef uint SeedStorageType;
|
---|
2527 | # endif
|
---|
2528 |
|
---|
2529 | typedef QThreadStorage<SeedStorageType *> SeedStorage;
|
---|
2530 | Q_GLOBAL_STATIC(SeedStorage, randTLS) // Thread Local Storage for seed value
|
---|
2531 |
|
---|
2532 | #endif
|
---|
2533 |
|
---|
2534 | /*!
|
---|
2535 | \relates <QtGlobal>
|
---|
2536 | \since 4.2
|
---|
2537 |
|
---|
2538 | Thread-safe version of the standard C++ \c srand() function.
|
---|
2539 |
|
---|
2540 | Sets the argument \a seed to be used to generate a new random number sequence of
|
---|
2541 | pseudo random integers to be returned by qrand().
|
---|
2542 |
|
---|
2543 | The sequence of random numbers generated is deterministic per thread. For example,
|
---|
2544 | if two threads call qsrand(1) and subsequently calls qrand(), the threads will get
|
---|
2545 | the same random number sequence.
|
---|
2546 |
|
---|
2547 | \sa qrand()
|
---|
2548 | */
|
---|
2549 | void qsrand(uint seed)
|
---|
2550 | {
|
---|
2551 | #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && !defined(Q_OS_SYMBIAN)
|
---|
2552 | SeedStorage *seedStorage = randTLS();
|
---|
2553 | if (seedStorage) {
|
---|
2554 | SeedStorageType *pseed = seedStorage->localData();
|
---|
2555 | if (!pseed)
|
---|
2556 | seedStorage->setLocalData(pseed = new SeedStorageType);
|
---|
2557 | *pseed = seed;
|
---|
2558 | } else {
|
---|
2559 | //golbal static seed storage should always exist,
|
---|
2560 | //except after being deleted by QGlobalStaticDeleter.
|
---|
2561 | //But since it still can be called from destructor of another
|
---|
2562 | //global static object, fallback to sqrand(seed)
|
---|
2563 | srand(seed);
|
---|
2564 | }
|
---|
2565 | #else
|
---|
2566 | // On Windows and Symbian srand() and rand() already use Thread-Local-Storage
|
---|
2567 | // to store the seed between calls
|
---|
2568 | // this is also valid for QT_NO_THREAD
|
---|
2569 | srand(seed);
|
---|
2570 | #endif
|
---|
2571 | }
|
---|
2572 |
|
---|
2573 | /*! \internal
|
---|
2574 | \relates <QtGlobal>
|
---|
2575 | \since 4.6
|
---|
2576 |
|
---|
2577 | Seed the PRNG, but only if it has not already been seeded.
|
---|
2578 |
|
---|
2579 | The default seed is a combination of current time, a stack address and a
|
---|
2580 | serial counter (since thread stack addresses are re-used).
|
---|
2581 | */
|
---|
2582 | void qsrand()
|
---|
2583 | {
|
---|
2584 | #if (defined(Q_OS_UNIX) || defined(Q_OS_WIN)) && !defined(QT_NO_THREAD)
|
---|
2585 | SeedStorage *seedStorage = randTLS();
|
---|
2586 | if (seedStorage) {
|
---|
2587 | SeedStorageType *pseed = seedStorage->localData();
|
---|
2588 | if (pseed) {
|
---|
2589 | // already seeded
|
---|
2590 | return;
|
---|
2591 | }
|
---|
2592 | seedStorage->setLocalData(pseed = new SeedStorageType);
|
---|
2593 | // start beyond 1 to avoid the sequence reset
|
---|
2594 | static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2);
|
---|
2595 | *pseed = QDateTime::currentDateTime().toTime_t()
|
---|
2596 | + quintptr(&pseed)
|
---|
2597 | + serial.fetchAndAddRelaxed(1);
|
---|
2598 | #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
|
---|
2599 | // for Windows and Symbian the srand function must still be called.
|
---|
2600 | srand(*pseed);
|
---|
2601 | #endif
|
---|
2602 | }
|
---|
2603 |
|
---|
2604 | //QT_NO_THREAD implementations
|
---|
2605 | #else
|
---|
2606 | static unsigned int seed = 0;
|
---|
2607 |
|
---|
2608 | if (seed)
|
---|
2609 | return;
|
---|
2610 |
|
---|
2611 | #if defined(Q_OS_SYMBIAN)
|
---|
2612 | seed = Math::Random();
|
---|
2613 | #elif defined(Q_OS_WIN)
|
---|
2614 | seed = GetTickCount();
|
---|
2615 | #else
|
---|
2616 | seed = quintptr(&seed) + QDateTime::currentDateTime().toTime_t();
|
---|
2617 | #endif
|
---|
2618 | srand(seed);
|
---|
2619 | #endif // defined(Q_OS_UNIX) || defined(Q_OS_WIN)) && !defined(QT_NO_THREAD)
|
---|
2620 | }
|
---|
2621 |
|
---|
2622 | /*!
|
---|
2623 | \relates <QtGlobal>
|
---|
2624 | \since 4.2
|
---|
2625 |
|
---|
2626 | Thread-safe version of the standard C++ \c rand() function.
|
---|
2627 |
|
---|
2628 | Returns a value between 0 and \c RAND_MAX (defined in \c <cstdlib> and
|
---|
2629 | \c <stdlib.h>), the next number in the current sequence of pseudo-random
|
---|
2630 | integers.
|
---|
2631 |
|
---|
2632 | Use \c qsrand() to initialize the pseudo-random number generator with
|
---|
2633 | a seed value.
|
---|
2634 |
|
---|
2635 | \sa qsrand()
|
---|
2636 | */
|
---|
2637 | int qrand()
|
---|
2638 | {
|
---|
2639 | #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD) && !defined(Q_OS_SYMBIAN)
|
---|
2640 | SeedStorage *seedStorage = randTLS();
|
---|
2641 | if (seedStorage) {
|
---|
2642 | SeedStorageType *pseed = seedStorage->localData();
|
---|
2643 | if (!pseed) {
|
---|
2644 | seedStorage->setLocalData(pseed = new SeedStorageType);
|
---|
2645 | *pseed = 1;
|
---|
2646 | }
|
---|
2647 | return rand_r(pseed);
|
---|
2648 | } else {
|
---|
2649 | //golbal static seed storage should always exist,
|
---|
2650 | //except after being deleted by QGlobalStaticDeleter.
|
---|
2651 | //But since it still can be called from destructor of another
|
---|
2652 | //global static object, fallback to qrand()
|
---|
2653 | return rand();
|
---|
2654 | }
|
---|
2655 | #else
|
---|
2656 | // On Windows and Symbian srand() and rand() already use Thread-Local-Storage
|
---|
2657 | // to store the seed between calls
|
---|
2658 | // this is also valid for QT_NO_THREAD
|
---|
2659 | return rand();
|
---|
2660 | #endif
|
---|
2661 | }
|
---|
2662 |
|
---|
2663 | /*!
|
---|
2664 | \macro forever
|
---|
2665 | \relates <QtGlobal>
|
---|
2666 |
|
---|
2667 | This macro is provided for convenience for writing infinite
|
---|
2668 | loops.
|
---|
2669 |
|
---|
2670 | Example:
|
---|
2671 |
|
---|
2672 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 31
|
---|
2673 |
|
---|
2674 | It is equivalent to \c{for (;;)}.
|
---|
2675 |
|
---|
2676 | If you're worried about namespace pollution, you can disable this
|
---|
2677 | macro by adding the following line to your \c .pro file:
|
---|
2678 |
|
---|
2679 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 32
|
---|
2680 |
|
---|
2681 | \sa Q_FOREVER
|
---|
2682 | */
|
---|
2683 |
|
---|
2684 | /*!
|
---|
2685 | \macro Q_FOREVER
|
---|
2686 | \relates <QtGlobal>
|
---|
2687 |
|
---|
2688 | Same as \l{forever}.
|
---|
2689 |
|
---|
2690 | This macro is available even when \c no_keywords is specified
|
---|
2691 | using the \c .pro file's \c CONFIG variable.
|
---|
2692 |
|
---|
2693 | \sa foreach()
|
---|
2694 | */
|
---|
2695 |
|
---|
2696 | /*!
|
---|
2697 | \macro foreach(variable, container)
|
---|
2698 | \relates <QtGlobal>
|
---|
2699 |
|
---|
2700 | This macro is used to implement Qt's \c foreach loop. The \a
|
---|
2701 | variable parameter is a variable name or variable definition; the
|
---|
2702 | \a container parameter is a Qt container whose value type
|
---|
2703 | corresponds to the type of the variable. See \l{The foreach
|
---|
2704 | Keyword} for details.
|
---|
2705 |
|
---|
2706 | If you're worried about namespace pollution, you can disable this
|
---|
2707 | macro by adding the following line to your \c .pro file:
|
---|
2708 |
|
---|
2709 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 33
|
---|
2710 |
|
---|
2711 | \sa Q_FOREACH()
|
---|
2712 | */
|
---|
2713 |
|
---|
2714 | /*!
|
---|
2715 | \macro Q_FOREACH(variable, container)
|
---|
2716 | \relates <QtGlobal>
|
---|
2717 |
|
---|
2718 | Same as foreach(\a variable, \a container).
|
---|
2719 |
|
---|
2720 | This macro is available even when \c no_keywords is specified
|
---|
2721 | using the \c .pro file's \c CONFIG variable.
|
---|
2722 |
|
---|
2723 | \sa foreach()
|
---|
2724 | */
|
---|
2725 |
|
---|
2726 | /*!
|
---|
2727 | \macro QT_TR_NOOP(sourceText)
|
---|
2728 | \relates <QtGlobal>
|
---|
2729 |
|
---|
2730 | Marks the string literal \a sourceText for dynamic translation in
|
---|
2731 | the current context (class), i.e the stored \a sourceText will not
|
---|
2732 | be altered.
|
---|
2733 |
|
---|
2734 | The macro expands to \a sourceText.
|
---|
2735 |
|
---|
2736 | Example:
|
---|
2737 |
|
---|
2738 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 34
|
---|
2739 |
|
---|
2740 | The macro QT_TR_NOOP_UTF8() is identical except that it tells lupdate
|
---|
2741 | that the source string is encoded in UTF-8. Corresponding variants
|
---|
2742 | exist in the QT_TRANSLATE_NOOP() family of macros, too. Note that
|
---|
2743 | using these macros is not required if \c CODECFORTR is already set to
|
---|
2744 | UTF-8 in the qmake project file.
|
---|
2745 |
|
---|
2746 | \sa QT_TRANSLATE_NOOP(), {Internationalization with Qt}
|
---|
2747 | */
|
---|
2748 |
|
---|
2749 | /*!
|
---|
2750 | \macro QT_TRANSLATE_NOOP(context, sourceText)
|
---|
2751 | \relates <QtGlobal>
|
---|
2752 |
|
---|
2753 | Marks the string literal \a sourceText for dynamic translation in
|
---|
2754 | the given \a context; i.e, the stored \a sourceText will not be
|
---|
2755 | altered. The \a context is typically a class and also needs to
|
---|
2756 | be specified as string literal.
|
---|
2757 |
|
---|
2758 | The macro expands to \a sourceText.
|
---|
2759 |
|
---|
2760 | Example:
|
---|
2761 |
|
---|
2762 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 35
|
---|
2763 |
|
---|
2764 | \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP3(), {Internationalization with Qt}
|
---|
2765 | */
|
---|
2766 |
|
---|
2767 | /*!
|
---|
2768 | \macro QT_TRANSLATE_NOOP3(context, sourceText, comment)
|
---|
2769 | \relates <QtGlobal>
|
---|
2770 | \since 4.4
|
---|
2771 |
|
---|
2772 | Marks the string literal \a sourceText for dynamic translation in the
|
---|
2773 | given \a context and with \a comment, i.e the stored \a sourceText will
|
---|
2774 | not be altered. The \a context is typically a class and also needs to
|
---|
2775 | be specified as string literal. The string literal \a comment
|
---|
2776 | will be available for translators using e.g. Qt Linguist.
|
---|
2777 |
|
---|
2778 | The macro expands to anonymous struct of the two string
|
---|
2779 | literals passed as \a sourceText and \a comment.
|
---|
2780 |
|
---|
2781 | Example:
|
---|
2782 |
|
---|
2783 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 36
|
---|
2784 |
|
---|
2785 | \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP(), {Internationalization with Qt}
|
---|
2786 | */
|
---|
2787 |
|
---|
2788 | /*!
|
---|
2789 | \fn QString qtTrId(const char *id, int n = -1)
|
---|
2790 | \relates <QtGlobal>
|
---|
2791 | \reentrant
|
---|
2792 | \since 4.6
|
---|
2793 |
|
---|
2794 | \brief The qtTrId function finds and returns a translated string.
|
---|
2795 |
|
---|
2796 | Returns a translated string identified by \a id.
|
---|
2797 | If no matching string is found, the id itself is returned. This
|
---|
2798 | should not happen under normal conditions.
|
---|
2799 |
|
---|
2800 | If \a n >= 0, all occurrences of \c %n in the resulting string
|
---|
2801 | are replaced with a decimal representation of \a n. In addition,
|
---|
2802 | depending on \a n's value, the translation text may vary.
|
---|
2803 |
|
---|
2804 | Meta data and comments can be passed as documented for QObject::tr().
|
---|
2805 | In addition, it is possible to supply a source string template like that:
|
---|
2806 |
|
---|
2807 | \tt{//% <C string>}
|
---|
2808 |
|
---|
2809 | or
|
---|
2810 |
|
---|
2811 | \tt{\begincomment% <C string> \endcomment}
|
---|
2812 |
|
---|
2813 | Example:
|
---|
2814 |
|
---|
2815 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qttrid
|
---|
2816 |
|
---|
2817 | Creating QM files suitable for use with this function requires passing
|
---|
2818 | the \c -idbased option to the \c lrelease tool.
|
---|
2819 |
|
---|
2820 | \warning This method is reentrant only if all translators are
|
---|
2821 | installed \e before calling this method. Installing or removing
|
---|
2822 | translators while performing translations is not supported. Doing
|
---|
2823 | so will probably result in crashes or other undesirable behavior.
|
---|
2824 |
|
---|
2825 | \sa QObject::tr(), QCoreApplication::translate(), {Internationalization with Qt}
|
---|
2826 | */
|
---|
2827 |
|
---|
2828 | /*!
|
---|
2829 | \macro QT_TRID_NOOP(id)
|
---|
2830 | \relates <QtGlobal>
|
---|
2831 | \since 4.6
|
---|
2832 |
|
---|
2833 | \brief The QT_TRID_NOOP macro marks an id for dynamic translation.
|
---|
2834 |
|
---|
2835 | The only purpose of this macro is to provide an anchor for attaching
|
---|
2836 | meta data like to qtTrId().
|
---|
2837 |
|
---|
2838 | The macro expands to \a id.
|
---|
2839 |
|
---|
2840 | Example:
|
---|
2841 |
|
---|
2842 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qttrid_noop
|
---|
2843 |
|
---|
2844 | \sa qtTrId(), {Internationalization with Qt}
|
---|
2845 | */
|
---|
2846 |
|
---|
2847 | /*!
|
---|
2848 | \macro QT_POINTER_SIZE
|
---|
2849 | \relates <QtGlobal>
|
---|
2850 |
|
---|
2851 | Expands to the size of a pointer in bytes (4 or 8). This is
|
---|
2852 | equivalent to \c sizeof(void *) but can be used in a preprocessor
|
---|
2853 | directive.
|
---|
2854 | */
|
---|
2855 |
|
---|
2856 | /*!
|
---|
2857 | \macro TRUE
|
---|
2858 | \relates <QtGlobal>
|
---|
2859 | \obsolete
|
---|
2860 |
|
---|
2861 | Synonym for \c true.
|
---|
2862 |
|
---|
2863 | \sa FALSE
|
---|
2864 | */
|
---|
2865 |
|
---|
2866 | /*!
|
---|
2867 | \macro FALSE
|
---|
2868 | \relates <QtGlobal>
|
---|
2869 | \obsolete
|
---|
2870 |
|
---|
2871 | Synonym for \c false.
|
---|
2872 |
|
---|
2873 | \sa TRUE
|
---|
2874 | */
|
---|
2875 |
|
---|
2876 | /*!
|
---|
2877 | \macro QABS(n)
|
---|
2878 | \relates <QtGlobal>
|
---|
2879 | \obsolete
|
---|
2880 |
|
---|
2881 | Use qAbs(\a n) instead.
|
---|
2882 |
|
---|
2883 | \sa QMIN(), QMAX()
|
---|
2884 | */
|
---|
2885 |
|
---|
2886 | /*!
|
---|
2887 | \macro QMIN(x, y)
|
---|
2888 | \relates <QtGlobal>
|
---|
2889 | \obsolete
|
---|
2890 |
|
---|
2891 | Use qMin(\a x, \a y) instead.
|
---|
2892 |
|
---|
2893 | \sa QMAX(), QABS()
|
---|
2894 | */
|
---|
2895 |
|
---|
2896 | /*!
|
---|
2897 | \macro QMAX(x, y)
|
---|
2898 | \relates <QtGlobal>
|
---|
2899 | \obsolete
|
---|
2900 |
|
---|
2901 | Use qMax(\a x, \a y) instead.
|
---|
2902 |
|
---|
2903 | \sa QMIN(), QABS()
|
---|
2904 | */
|
---|
2905 |
|
---|
2906 | /*!
|
---|
2907 | \macro const char *qPrintable(const QString &str)
|
---|
2908 | \relates <QtGlobal>
|
---|
2909 |
|
---|
2910 | Returns \a str as a \c{const char *}. This is equivalent to
|
---|
2911 | \a{str}.toLocal8Bit().constData().
|
---|
2912 |
|
---|
2913 | The char pointer will be invalid after the statement in which
|
---|
2914 | qPrintable() is used. This is because the array returned by
|
---|
2915 | toLocal8Bit() will fall out of scope.
|
---|
2916 |
|
---|
2917 | Example:
|
---|
2918 |
|
---|
2919 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 37
|
---|
2920 |
|
---|
2921 |
|
---|
2922 | \sa qDebug(), qWarning(), qCritical(), qFatal()
|
---|
2923 | */
|
---|
2924 |
|
---|
2925 | /*!
|
---|
2926 | \macro Q_DECLARE_TYPEINFO(Type, Flags)
|
---|
2927 | \relates <QtGlobal>
|
---|
2928 |
|
---|
2929 | You can use this macro to specify information about a custom type
|
---|
2930 | \a Type. With accurate type information, Qt's \l{generic
|
---|
2931 | containers} can choose appropriate storage methods and algorithms.
|
---|
2932 |
|
---|
2933 | \a Flags can be one of the following:
|
---|
2934 |
|
---|
2935 | \list
|
---|
2936 | \o \c Q_PRIMITIVE_TYPE specifies that \a Type is a POD (plain old
|
---|
2937 | data) type with no constructor or destructor.
|
---|
2938 | \o \c Q_MOVABLE_TYPE specifies that \a Type has a constructor
|
---|
2939 | and/or a destructor but can be moved in memory using \c
|
---|
2940 | memcpy().
|
---|
2941 | \o \c Q_COMPLEX_TYPE (the default) specifies that \a Type has
|
---|
2942 | constructors and/or a destructor and that it may not be moved
|
---|
2943 | in memory.
|
---|
2944 | \endlist
|
---|
2945 |
|
---|
2946 | Example of a "primitive" type:
|
---|
2947 |
|
---|
2948 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 38
|
---|
2949 |
|
---|
2950 | Example of a movable type:
|
---|
2951 |
|
---|
2952 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 39
|
---|
2953 | */
|
---|
2954 |
|
---|
2955 | /*!
|
---|
2956 | \macro Q_UNUSED(name)
|
---|
2957 | \relates <QtGlobal>
|
---|
2958 |
|
---|
2959 | Indicates to the compiler that the parameter with the specified
|
---|
2960 | \a name is not used in the body of a function. This can be used to
|
---|
2961 | suppress compiler warnings while allowing functions to be defined
|
---|
2962 | with meaningful parameter names in their signatures.
|
---|
2963 | */
|
---|
2964 |
|
---|
2965 | #if defined(QT3_SUPPORT) && !defined(QT_NO_SETTINGS)
|
---|
2966 | QT_BEGIN_INCLUDE_NAMESPACE
|
---|
2967 | #include <qlibraryinfo.h>
|
---|
2968 | QT_END_INCLUDE_NAMESPACE
|
---|
2969 |
|
---|
2970 | static const char *qInstallLocation(QLibraryInfo::LibraryLocation loc)
|
---|
2971 | {
|
---|
2972 | static QByteArray ret;
|
---|
2973 | ret = QLibraryInfo::location(loc).toLatin1();
|
---|
2974 | return ret.constData();
|
---|
2975 | }
|
---|
2976 | const char *qInstallPath()
|
---|
2977 | {
|
---|
2978 | return qInstallLocation(QLibraryInfo::PrefixPath);
|
---|
2979 | }
|
---|
2980 | const char *qInstallPathDocs()
|
---|
2981 | {
|
---|
2982 | return qInstallLocation(QLibraryInfo::DocumentationPath);
|
---|
2983 | }
|
---|
2984 | const char *qInstallPathHeaders()
|
---|
2985 | {
|
---|
2986 | return qInstallLocation(QLibraryInfo::HeadersPath);
|
---|
2987 | }
|
---|
2988 | const char *qInstallPathLibs()
|
---|
2989 | {
|
---|
2990 | return qInstallLocation(QLibraryInfo::LibrariesPath);
|
---|
2991 | }
|
---|
2992 | const char *qInstallPathBins()
|
---|
2993 | {
|
---|
2994 | return qInstallLocation(QLibraryInfo::BinariesPath);
|
---|
2995 | }
|
---|
2996 | const char *qInstallPathPlugins()
|
---|
2997 | {
|
---|
2998 | return qInstallLocation(QLibraryInfo::PluginsPath);
|
---|
2999 | }
|
---|
3000 | const char *qInstallPathData()
|
---|
3001 | {
|
---|
3002 | return qInstallLocation(QLibraryInfo::DataPath);
|
---|
3003 | }
|
---|
3004 | const char *qInstallPathTranslations()
|
---|
3005 | {
|
---|
3006 | return qInstallLocation(QLibraryInfo::TranslationsPath);
|
---|
3007 | }
|
---|
3008 | const char *qInstallPathSysconf()
|
---|
3009 | {
|
---|
3010 | return qInstallLocation(QLibraryInfo::SettingsPath);
|
---|
3011 | }
|
---|
3012 | #endif
|
---|
3013 |
|
---|
3014 | struct QInternal_CallBackTable {
|
---|
3015 | QVector<QList<qInternalCallback> > callbacks;
|
---|
3016 | };
|
---|
3017 |
|
---|
3018 | Q_GLOBAL_STATIC(QInternal_CallBackTable, global_callback_table)
|
---|
3019 |
|
---|
3020 | bool QInternal::registerCallback(Callback cb, qInternalCallback callback)
|
---|
3021 | {
|
---|
3022 | if (cb >= 0 && cb < QInternal::LastCallback) {
|
---|
3023 | QInternal_CallBackTable *cbt = global_callback_table();
|
---|
3024 | cbt->callbacks.resize(cb + 1);
|
---|
3025 | cbt->callbacks[cb].append(callback);
|
---|
3026 | return true;
|
---|
3027 | }
|
---|
3028 | return false;
|
---|
3029 | }
|
---|
3030 |
|
---|
3031 | bool QInternal::unregisterCallback(Callback cb, qInternalCallback callback)
|
---|
3032 | {
|
---|
3033 | if (cb >= 0 && cb < QInternal::LastCallback) {
|
---|
3034 | QInternal_CallBackTable *cbt = global_callback_table();
|
---|
3035 | return (bool) cbt->callbacks[cb].removeAll(callback);
|
---|
3036 | }
|
---|
3037 | return false;
|
---|
3038 | }
|
---|
3039 |
|
---|
3040 | bool QInternal::activateCallbacks(Callback cb, void **parameters)
|
---|
3041 | {
|
---|
3042 | Q_ASSERT_X(cb >= 0, "QInternal::activateCallback()", "Callback id must be a valid id");
|
---|
3043 |
|
---|
3044 | QInternal_CallBackTable *cbt = global_callback_table();
|
---|
3045 | if (cbt && cb < cbt->callbacks.size()) {
|
---|
3046 | QList<qInternalCallback> callbacks = cbt->callbacks[cb];
|
---|
3047 | bool ret = false;
|
---|
3048 | for (int i=0; i<callbacks.size(); ++i)
|
---|
3049 | ret |= (callbacks.at(i))(parameters);
|
---|
3050 | return ret;
|
---|
3051 | }
|
---|
3052 | return false;
|
---|
3053 | }
|
---|
3054 |
|
---|
3055 | extern void qt_set_current_thread_to_main_thread();
|
---|
3056 |
|
---|
3057 | bool QInternal::callFunction(InternalFunction func, void **args)
|
---|
3058 | {
|
---|
3059 | Q_ASSERT_X(func >= 0,
|
---|
3060 | "QInternal::callFunction()", "Callback id must be a valid id");
|
---|
3061 | #ifndef QT_NO_QOBJECT
|
---|
3062 | switch (func) {
|
---|
3063 | #ifndef QT_NO_THREAD
|
---|
3064 | case QInternal::CreateThreadForAdoption:
|
---|
3065 | *args = QAdoptedThread::createThreadForAdoption();
|
---|
3066 | return true;
|
---|
3067 | #endif
|
---|
3068 | case QInternal::RefAdoptedThread:
|
---|
3069 | QThreadData::get2((QThread *) *args)->ref();
|
---|
3070 | return true;
|
---|
3071 | case QInternal::DerefAdoptedThread:
|
---|
3072 | QThreadData::get2((QThread *) *args)->deref();
|
---|
3073 | return true;
|
---|
3074 | case QInternal::SetCurrentThreadToMainThread:
|
---|
3075 | qt_set_current_thread_to_main_thread();
|
---|
3076 | return true;
|
---|
3077 | case QInternal::SetQObjectSender: {
|
---|
3078 | QObject *receiver = (QObject *) args[0];
|
---|
3079 | QObjectPrivate::Sender *sender = new QObjectPrivate::Sender;
|
---|
3080 | sender->sender = (QObject *) args[1];
|
---|
3081 | sender->signal = *(int *) args[2];
|
---|
3082 | sender->ref = 1;
|
---|
3083 |
|
---|
3084 | // Store the old sender as "return value"
|
---|
3085 | args[3] = QObjectPrivate::setCurrentSender(receiver, sender);
|
---|
3086 | args[4] = sender;
|
---|
3087 | return true;
|
---|
3088 | }
|
---|
3089 | case QInternal::GetQObjectSender: {
|
---|
3090 | QObject *receiver = (QObject *) args[0];
|
---|
3091 | QObjectPrivate *d = QObjectPrivate::get(receiver);
|
---|
3092 | args[1] = d->currentSender ? d->currentSender->sender : 0;
|
---|
3093 | return true;
|
---|
3094 | }
|
---|
3095 | case QInternal::ResetQObjectSender: {
|
---|
3096 | QObject *receiver = (QObject *) args[0];
|
---|
3097 | QObjectPrivate::Sender *oldSender = (QObjectPrivate::Sender *) args[1];
|
---|
3098 | QObjectPrivate::Sender *sender = (QObjectPrivate::Sender *) args[2];
|
---|
3099 | QObjectPrivate::resetCurrentSender(receiver, sender, oldSender);
|
---|
3100 | delete sender;
|
---|
3101 | return true;
|
---|
3102 | }
|
---|
3103 |
|
---|
3104 | default:
|
---|
3105 | break;
|
---|
3106 | }
|
---|
3107 | #else
|
---|
3108 | Q_UNUSED(args);
|
---|
3109 | Q_UNUSED(func);
|
---|
3110 | #endif
|
---|
3111 |
|
---|
3112 | return false;
|
---|
3113 | }
|
---|
3114 |
|
---|
3115 | /*!
|
---|
3116 | \macro Q_BYTE_ORDER
|
---|
3117 | \relates <QtGlobal>
|
---|
3118 |
|
---|
3119 | This macro can be used to determine the byte order your system
|
---|
3120 | uses for storing data in memory. i.e., whether your system is
|
---|
3121 | little-endian or big-endian. It is set by Qt to one of the macros
|
---|
3122 | Q_LITTLE_ENDIAN or Q_BIG_ENDIAN. You normally won't need to worry
|
---|
3123 | about endian-ness, but you might, for example if you need to know
|
---|
3124 | which byte of an integer or UTF-16 character is stored in the
|
---|
3125 | lowest address. Endian-ness is important in networking, where
|
---|
3126 | computers with different values for Q_BYTE_ORDER must pass data
|
---|
3127 | back and forth.
|
---|
3128 |
|
---|
3129 | Use this macro as in the following examples.
|
---|
3130 |
|
---|
3131 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 40
|
---|
3132 |
|
---|
3133 | \sa Q_BIG_ENDIAN, Q_LITTLE_ENDIAN
|
---|
3134 | */
|
---|
3135 |
|
---|
3136 | /*!
|
---|
3137 | \macro Q_LITTLE_ENDIAN
|
---|
3138 | \relates <QtGlobal>
|
---|
3139 |
|
---|
3140 | This macro represents a value you can compare to the macro
|
---|
3141 | Q_BYTE_ORDER to determine the endian-ness of your system. In a
|
---|
3142 | little-endian system, the least significant byte is stored at the
|
---|
3143 | lowest address. The other bytes follow in increasing order of
|
---|
3144 | significance.
|
---|
3145 |
|
---|
3146 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 41
|
---|
3147 |
|
---|
3148 | \sa Q_BYTE_ORDER, Q_BIG_ENDIAN
|
---|
3149 | */
|
---|
3150 |
|
---|
3151 | /*!
|
---|
3152 | \macro Q_BIG_ENDIAN
|
---|
3153 | \relates <QtGlobal>
|
---|
3154 |
|
---|
3155 | This macro represents a value you can compare to the macro
|
---|
3156 | Q_BYTE_ORDER to determine the endian-ness of your system. In a
|
---|
3157 | big-endian system, the most significant byte is stored at the
|
---|
3158 | lowest address. The other bytes follow in decreasing order of
|
---|
3159 | significance.
|
---|
3160 |
|
---|
3161 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 42
|
---|
3162 |
|
---|
3163 | \sa Q_BYTE_ORDER, Q_LITTLE_ENDIAN
|
---|
3164 | */
|
---|
3165 |
|
---|
3166 | /*!
|
---|
3167 | \macro Q_GLOBAL_STATIC(type, name)
|
---|
3168 | \internal
|
---|
3169 |
|
---|
3170 | Declares a global static variable with the given \a type and \a name.
|
---|
3171 |
|
---|
3172 | Use this macro to instantiate an object in a thread-safe way, creating
|
---|
3173 | a global pointer that can be used to refer to it.
|
---|
3174 |
|
---|
3175 | \warning This macro is subject to a race condition that can cause the object
|
---|
3176 | to be constructed twice. However, if this occurs, the second instance will
|
---|
3177 | be immediately deleted.
|
---|
3178 |
|
---|
3179 | See also
|
---|
3180 | \l{http://www.aristeia.com/publications.html}{"C++ and the perils of Double-Checked Locking"}
|
---|
3181 | by Scott Meyers and Andrei Alexandrescu.
|
---|
3182 | */
|
---|
3183 |
|
---|
3184 | /*!
|
---|
3185 | \macro Q_GLOBAL_STATIC_WITH_ARGS(type, name, arguments)
|
---|
3186 | \internal
|
---|
3187 |
|
---|
3188 | Declares a global static variable with the specified \a type and \a name.
|
---|
3189 |
|
---|
3190 | Use this macro to instantiate an object using the \a arguments specified
|
---|
3191 | in a thread-safe way, creating a global pointer that can be used to refer
|
---|
3192 | to it.
|
---|
3193 |
|
---|
3194 | \warning This macro is subject to a race condition that can cause the object
|
---|
3195 | to be constructed twice. However, if this occurs, the second instance will
|
---|
3196 | be immediately deleted.
|
---|
3197 |
|
---|
3198 | See also
|
---|
3199 | \l{http://www.aristeia.com/publications.html}{"C++ and the perils of Double-Checked Locking"}
|
---|
3200 | by Scott Meyers and Andrei Alexandrescu.
|
---|
3201 | */
|
---|
3202 |
|
---|
3203 | /*!
|
---|
3204 | \macro QT_NAMESPACE
|
---|
3205 | \internal
|
---|
3206 |
|
---|
3207 | If this macro is defined to \c ns all Qt classes are put in a namespace
|
---|
3208 | called \c ns. Also, moc will output code putting metaobjects etc.
|
---|
3209 | into namespace \c ns.
|
---|
3210 |
|
---|
3211 | \sa QT_BEGIN_NAMESPACE, QT_END_NAMESPACE,
|
---|
3212 | QT_PREPEND_NAMESPACE, QT_USE_NAMESPACE,
|
---|
3213 | QT_BEGIN_INCLUDE_NAMESPACE, QT_END_INCLUDE_NAMESPACE,
|
---|
3214 | QT_BEGIN_MOC_NAMESPACE, QT_END_MOC_NAMESPACE,
|
---|
3215 | */
|
---|
3216 |
|
---|
3217 | /*!
|
---|
3218 | \macro QT_PREPEND_NAMESPACE(identifier)
|
---|
3219 | \internal
|
---|
3220 |
|
---|
3221 | This macro qualifies \a identifier with the full namespace.
|
---|
3222 | It expands to \c{::QT_NAMESPACE::identifier} if \c QT_NAMESPACE is defined
|
---|
3223 | and only \a identifier otherwise.
|
---|
3224 |
|
---|
3225 | \sa QT_NAMESPACE
|
---|
3226 | */
|
---|
3227 |
|
---|
3228 | /*!
|
---|
3229 | \macro QT_USE_NAMESPACE
|
---|
3230 | \internal
|
---|
3231 |
|
---|
3232 | This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined
|
---|
3233 | and nothing otherwise.
|
---|
3234 |
|
---|
3235 | \sa QT_NAMESPACE
|
---|
3236 | */
|
---|
3237 |
|
---|
3238 | /*!
|
---|
3239 | \macro QT_BEGIN_NAMESPACE
|
---|
3240 | \internal
|
---|
3241 |
|
---|
3242 | This macro expands to
|
---|
3243 |
|
---|
3244 | \snippet snippets/code/src_corelib_global_qglobal.cpp begin namespace macro
|
---|
3245 |
|
---|
3246 | if \c QT_NAMESPACE is defined and nothing otherwise. If should always
|
---|
3247 | appear in the file-level scope and be followed by \c QT_END_NAMESPACE
|
---|
3248 | at the same logical level with respect to preprocessor conditionals
|
---|
3249 | in the same file.
|
---|
3250 |
|
---|
3251 | As a rule of thumb, \c QT_BEGIN_NAMESPACE should appear in all Qt header
|
---|
3252 | and Qt source files after the last \c{#include} line and before the first
|
---|
3253 | declaration. In Qt headers using \c QT_BEGIN_HEADER, \c QT_BEGIN_NAMESPACE
|
---|
3254 | follows \c QT_BEGIN_HEADER immediately.
|
---|
3255 |
|
---|
3256 | If that rule can't be followed because, e.g., \c{#include} lines and
|
---|
3257 | declarations are wildly mixed, place \c QT_BEGIN_NAMESPACE before
|
---|
3258 | the first declaration and wrap the \c{#include} lines in
|
---|
3259 | \c QT_BEGIN_INCLUDE_NAMESPACE and \c QT_END_INCLUDE_NAMESPACE.
|
---|
3260 |
|
---|
3261 | When using the \c QT_NAMESPACE feature in user code
|
---|
3262 | (e.g., when building plugins statically linked to Qt) where
|
---|
3263 | the user code is not intended to go into the \c QT_NAMESPACE
|
---|
3264 | namespace, all forward declarations of Qt classes need to
|
---|
3265 | be wrapped in \c QT_BEGIN_NAMESPACE and \c QT_END_NAMESPACE.
|
---|
3266 | After that, a \c QT_USE_NAMESPACE should follow.
|
---|
3267 | No further changes should be needed.
|
---|
3268 |
|
---|
3269 | \sa QT_NAMESPACE
|
---|
3270 | */
|
---|
3271 |
|
---|
3272 | /*!
|
---|
3273 | \macro QT_END_NAMESPACE
|
---|
3274 | \internal
|
---|
3275 |
|
---|
3276 | This macro expands to
|
---|
3277 |
|
---|
3278 | \snippet snippets/code/src_corelib_global_qglobal.cpp end namespace macro
|
---|
3279 |
|
---|
3280 | if \c QT_NAMESPACE is defined and nothing otherwise. It is used to cancel
|
---|
3281 | the effect of \c QT_BEGIN_NAMESPACE.
|
---|
3282 |
|
---|
3283 | If a source file ends with a \c{#include} directive that includes a moc file,
|
---|
3284 | \c QT_END_NAMESPACE should be placed before that \c{#include}.
|
---|
3285 |
|
---|
3286 | \sa QT_NAMESPACE
|
---|
3287 | */
|
---|
3288 |
|
---|
3289 | /*!
|
---|
3290 | \macro QT_BEGIN_INCLUDE_NAMESPACE
|
---|
3291 | \internal
|
---|
3292 |
|
---|
3293 | This macro is equivalent to \c QT_END_NAMESPACE.
|
---|
3294 | It only serves as syntactic sugar and is intended
|
---|
3295 | to be used before #include lines within a
|
---|
3296 | \c QT_BEGIN_NAMESPACE ... \c QT_END_NAMESPACE block.
|
---|
3297 |
|
---|
3298 | \sa QT_NAMESPACE
|
---|
3299 | */
|
---|
3300 |
|
---|
3301 | /*!
|
---|
3302 | \macro QT_END_INCLUDE_NAMESPACE
|
---|
3303 | \internal
|
---|
3304 |
|
---|
3305 | This macro is equivalent to \c QT_BEGIN_NAMESPACE.
|
---|
3306 | It only serves as syntactic sugar and is intended
|
---|
3307 | to be used after #include lines within a
|
---|
3308 | \c QT_BEGIN_NAMESPACE ... \c QT_END_NAMESPACE block.
|
---|
3309 |
|
---|
3310 | \sa QT_NAMESPACE
|
---|
3311 | */
|
---|
3312 |
|
---|
3313 | /*!
|
---|
3314 | \macro QT_BEGIN_MOC_NAMESPACE
|
---|
3315 | \internal
|
---|
3316 |
|
---|
3317 | This macro is output by moc at the beginning of
|
---|
3318 | moc files. It is equivalent to \c QT_USE_NAMESPACE.
|
---|
3319 |
|
---|
3320 | \sa QT_NAMESPACE
|
---|
3321 | */
|
---|
3322 |
|
---|
3323 | /*!
|
---|
3324 | \macro QT_END_MOC_NAMESPACE
|
---|
3325 | \internal
|
---|
3326 |
|
---|
3327 | This macro is output by moc at the beginning of
|
---|
3328 | moc files. It expands to nothing.
|
---|
3329 |
|
---|
3330 | \sa QT_NAMESPACE
|
---|
3331 | */
|
---|
3332 |
|
---|
3333 | /*!
|
---|
3334 | \fn bool qFuzzyCompare(double p1, double p2)
|
---|
3335 | \relates <QtGlobal>
|
---|
3336 | \since 4.4
|
---|
3337 | \threadsafe
|
---|
3338 |
|
---|
3339 | Compares the floating point value \a p1 and \a p2 and
|
---|
3340 | returns \c true if they are considered equal, otherwise \c false.
|
---|
3341 |
|
---|
3342 | Note that comparing values where either \a p1 or \a p2 is 0.0 will not work.
|
---|
3343 | The solution to this is to compare against values greater than or equal to 1.0.
|
---|
3344 |
|
---|
3345 | \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 46
|
---|
3346 |
|
---|
3347 | The two numbers are compared in a relative way, where the
|
---|
3348 | exactness is stronger the smaller the numbers are.
|
---|
3349 | */
|
---|
3350 |
|
---|
3351 | /*!
|
---|
3352 | \fn bool qFuzzyCompare(float p1, float p2)
|
---|
3353 | \relates <QtGlobal>
|
---|
3354 | \since 4.4
|
---|
3355 | \threadsafe
|
---|
3356 |
|
---|
3357 | Compares the floating point value \a p1 and \a p2 and
|
---|
3358 | returns \c true if they are considered equal, otherwise \c false.
|
---|
3359 |
|
---|
3360 | The two numbers are compared in a relative way, where the
|
---|
3361 | exactness is stronger the smaller the numbers are.
|
---|
3362 | */
|
---|
3363 |
|
---|
3364 | /*!
|
---|
3365 | \macro QT_REQUIRE_VERSION(int argc, char **argv, const char *version)
|
---|
3366 | \relates <QtGlobal>
|
---|
3367 |
|
---|
3368 | This macro can be used to ensure that the application is run
|
---|
3369 | against a recent enough version of Qt. This is especially useful
|
---|
3370 | if your application depends on a specific bug fix introduced in a
|
---|
3371 | bug-fix release (e.g., 4.0.2).
|
---|
3372 |
|
---|
3373 | The \a argc and \a argv parameters are the \c main() function's
|
---|
3374 | \c argc and \c argv parameters. The \a version parameter is a
|
---|
3375 | string literal that specifies which version of Qt the application
|
---|
3376 | requires (e.g., "4.0.2").
|
---|
3377 |
|
---|
3378 | Example:
|
---|
3379 |
|
---|
3380 | \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 4
|
---|
3381 | */
|
---|
3382 |
|
---|
3383 | /*!
|
---|
3384 | \macro Q_DECL_EXPORT
|
---|
3385 | \relates <QtGlobal>
|
---|
3386 |
|
---|
3387 | This macro marks a symbol for shared library export (see
|
---|
3388 | \l{sharedlibrary.html}{Creating Shared Libraries}).
|
---|
3389 |
|
---|
3390 | \sa Q_DECL_IMPORT
|
---|
3391 | */
|
---|
3392 |
|
---|
3393 | /*!
|
---|
3394 | \macro Q_DECL_IMPORT
|
---|
3395 | \relates <QtGlobal>
|
---|
3396 |
|
---|
3397 | This macro declares a symbol to be an import from a shared library (see
|
---|
3398 | \l{sharedlibrary.html}{Creating Shared Libraries}).
|
---|
3399 |
|
---|
3400 | \sa Q_DECL_EXPORT
|
---|
3401 | */
|
---|
3402 |
|
---|
3403 | #if defined(Q_OS_SYMBIAN)
|
---|
3404 |
|
---|
3405 | #include <typeinfo>
|
---|
3406 |
|
---|
3407 | /*! \macro QT_TRAP_THROWING(function)
|
---|
3408 | \relates <QtGlobal>
|
---|
3409 | \ingroup qts60
|
---|
3410 |
|
---|
3411 | TRAP leaves from Symbian \a function and throws an appropriate
|
---|
3412 | standard C++ exception instead.
|
---|
3413 | This must be used when calling Symbian OS leaving functions
|
---|
3414 | from inside Qt or standard C++ code, so that the code can respond
|
---|
3415 | correctly to the exception.
|
---|
3416 |
|
---|
3417 | \warning This macro is only available on Symbian.
|
---|
3418 |
|
---|
3419 | Example:
|
---|
3420 |
|
---|
3421 | \code
|
---|
3422 | // A Symbian leaving function is being called within a Qt function.
|
---|
3423 | // Any leave must be converted to an exception
|
---|
3424 | CAknTitlePane* titlePane = S60->titlePane();
|
---|
3425 | if (titlePane) {
|
---|
3426 | TPtrC captionPtr(qt_QString2TPtrC(caption));
|
---|
3427 | QT_TRAP_THROWING(titlePane->SetTextL(captionPtr));
|
---|
3428 | }
|
---|
3429 | \endcode
|
---|
3430 |
|
---|
3431 | \sa QT_TRYCATCH_ERROR(), QT_TRYCATCH_LEAVING()
|
---|
3432 | */
|
---|
3433 |
|
---|
3434 | /*! \macro QT_TRYCATCH_ERROR(error, function)
|
---|
3435 | \relates <QtGlobal>
|
---|
3436 | \ingroup qts60
|
---|
3437 |
|
---|
3438 | Catch standard C++ exceptions from a \a function and convert them to a Symbian OS
|
---|
3439 | \a error code, or \c KErrNone if there is no exception.
|
---|
3440 | This must be used inside Qt or standard C++ code when using exception throwing
|
---|
3441 | code (practically anything) and returning an error code to Symbian OS.
|
---|
3442 |
|
---|
3443 | \warning This macro is only available on Symbian.
|
---|
3444 |
|
---|
3445 | Example:
|
---|
3446 |
|
---|
3447 | \code
|
---|
3448 | // An exception might be thrown in this Symbian TInt error returning function.
|
---|
3449 | // It is caught and translated to an error code
|
---|
3450 | TInt QServerApp::Connect(const QString &serverName)
|
---|
3451 | {
|
---|
3452 | TPtrC name;
|
---|
3453 | TInt err;
|
---|
3454 | QT_TRYCATCH_ERROR(err, name.Set(qt_QString2TPtrC(serverName)));
|
---|
3455 | if (err != KErrNone)
|
---|
3456 | return err;
|
---|
3457 | return iServer.Connect(name);
|
---|
3458 | }
|
---|
3459 | \endcode
|
---|
3460 | }
|
---|
3461 |
|
---|
3462 | \sa QT_TRYCATCH_LEAVING(), QT_TRAP_THROWING()
|
---|
3463 | */
|
---|
3464 |
|
---|
3465 | /*! \macro QT_TRYCATCH_LEAVING(function)
|
---|
3466 | \relates <QtGlobal>
|
---|
3467 | \ingroup qts60
|
---|
3468 |
|
---|
3469 | Catch standard C++ exceptions from \a function and convert them to Symbian OS
|
---|
3470 | leaves. This must be used inside Qt or standard C++ code when using exception
|
---|
3471 | throwing code (practically anything) and returning to Symbian OS from a leaving function.
|
---|
3472 | For example inside a Symbian active object's \c RunL function implemented with Qt code.
|
---|
3473 |
|
---|
3474 | \warning This macro is only available on Symbian.
|
---|
3475 |
|
---|
3476 | Example:
|
---|
3477 |
|
---|
3478 | \code
|
---|
3479 | // This active object signals Qt code
|
---|
3480 | // Exceptions from the Qt code must be converted to Symbian OS leaves for the active scheduler
|
---|
3481 | void QWakeUpActiveObject::RunL()
|
---|
3482 | {
|
---|
3483 | iStatus = KRequestPending;
|
---|
3484 | SetActive();
|
---|
3485 | QT_TRYCATCH_LEAVING(m_dispatcher->wakeUpWasCalled());
|
---|
3486 | }
|
---|
3487 | \endcode
|
---|
3488 |
|
---|
3489 | \sa QT_TRAP_THROWING(), QT_TRYCATCH_ERROR()
|
---|
3490 | */
|
---|
3491 |
|
---|
3492 | #include <stdexcept>
|
---|
3493 |
|
---|
3494 | class QSymbianLeaveException : public std::exception
|
---|
3495 | {
|
---|
3496 | public:
|
---|
3497 | inline QSymbianLeaveException(int err) : error(err) {}
|
---|
3498 | inline const char* what() const throw() { return "Symbian leave exception"; }
|
---|
3499 |
|
---|
3500 | public:
|
---|
3501 | int error;
|
---|
3502 | };
|
---|
3503 |
|
---|
3504 | /*! \relates <QtGlobal>
|
---|
3505 | \ingroup qts60
|
---|
3506 |
|
---|
3507 | Throws an exception if the \a error parameter is a symbian error code.
|
---|
3508 | This is the exception throwing equivalent of Symbian's User::LeaveIfError.
|
---|
3509 |
|
---|
3510 | \warning This function is only available on Symbian.
|
---|
3511 |
|
---|
3512 | \sa qt_symbian_exception2LeaveL(), qt_symbian_exception2Error()
|
---|
3513 | */
|
---|
3514 | void qt_symbian_throwIfError(int error)
|
---|
3515 | {
|
---|
3516 | if (error >= KErrNone)
|
---|
3517 | return; // do nothing - not an exception
|
---|
3518 | switch (error) {
|
---|
3519 | case KErrNoMemory:
|
---|
3520 | throw std::bad_alloc();
|
---|
3521 | case KErrArgument:
|
---|
3522 | throw std::invalid_argument("from Symbian error");
|
---|
3523 | case KErrOverflow:
|
---|
3524 | throw std::overflow_error("from Symbian error");
|
---|
3525 | case KErrUnderflow:
|
---|
3526 | throw std::underflow_error("from Symbian error");
|
---|
3527 | default:
|
---|
3528 | throw QSymbianLeaveException(error);
|
---|
3529 | }
|
---|
3530 | }
|
---|
3531 |
|
---|
3532 | /*! \relates <QtGlobal>
|
---|
3533 | \ingroup qts60
|
---|
3534 |
|
---|
3535 | Convert a caught standard C++ exception \a aThrow to a Symbian leave
|
---|
3536 |
|
---|
3537 | \warning This function is only available on Symbian.
|
---|
3538 |
|
---|
3539 | \sa qt_symbian_throwIfError(), qt_symbian_exception2Error()
|
---|
3540 | */
|
---|
3541 | void qt_symbian_exception2LeaveL(const std::exception& aThrow)
|
---|
3542 | {
|
---|
3543 | User::Leave(qt_symbian_exception2Error(aThrow));
|
---|
3544 | }
|
---|
3545 |
|
---|
3546 | /*! \relates <QtGlobal>
|
---|
3547 | \ingroup qts60
|
---|
3548 |
|
---|
3549 | Convert a caught standard C++ exception \a aThrow to a Symbian error code
|
---|
3550 |
|
---|
3551 | \warning This function is only available on Symbian.
|
---|
3552 |
|
---|
3553 | \sa qt_symbian_throwIfError(), qt_symbian_exception2LeaveL()
|
---|
3554 | */
|
---|
3555 | int qt_symbian_exception2Error(const std::exception& aThrow)
|
---|
3556 | {
|
---|
3557 | const std::type_info& atype = typeid(aThrow);
|
---|
3558 | int err = KErrGeneral;
|
---|
3559 |
|
---|
3560 | if(atype == typeid (std::bad_alloc))
|
---|
3561 | err = KErrNoMemory;
|
---|
3562 | else if(atype == typeid(QSymbianLeaveException))
|
---|
3563 | err = static_cast<const QSymbianLeaveException&>(aThrow).error;
|
---|
3564 | else {
|
---|
3565 | if(atype == typeid(std::invalid_argument))
|
---|
3566 | err = KErrArgument;
|
---|
3567 | else if(atype == typeid(std::out_of_range))
|
---|
3568 | // std::out_of_range is of type logic_error which by definition means that it is
|
---|
3569 | // "presumably detectable before the program executes".
|
---|
3570 | // std::out_of_range is used to report an argument is not within the expected range.
|
---|
3571 | // The description of KErrArgument says an argument is out of range. Hence the mapping.
|
---|
3572 | err = KErrArgument;
|
---|
3573 | else if(atype == typeid(std::overflow_error))
|
---|
3574 | err = KErrOverflow;
|
---|
3575 | else if(atype == typeid(std::underflow_error))
|
---|
3576 | err = KErrUnderflow;
|
---|
3577 | qWarning("translation from std exception \"%s\" to %d", aThrow.what(), err);
|
---|
3578 | }
|
---|
3579 |
|
---|
3580 | return err;
|
---|
3581 | }
|
---|
3582 | #endif
|
---|
3583 |
|
---|
3584 | QT_END_NAMESPACE
|
---|