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