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