source: trunk/src/corelib/global/qglobal.cpp@ 813

Last change on this file since 813 was 800, checked in by Dmitry A. Kuminov, 15 years ago

corelib: Include qt_os2.h in qglobal.cpp explicitly as we use its definitions (relying on the implicit inclusion is never safe).

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