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