1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2017 Intel Corporation.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#include "qplatformdefs.h"
42#include "qstring.h"
43#include "qvector.h"
44#include "qlist.h"
45#include "qdir.h"
46#include "qdatetime.h"
47#include "qoperatingsystemversion.h"
48#include "qoperatingsystemversion_p.h"
49#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN) || defined(Q_OS_WINRT)
50# include "qoperatingsystemversion_win_p.h"
51# ifndef Q_OS_WINRT
52# include "private/qwinregistry_p.h"
53# endif
54#endif // Q_OS_WIN || Q_OS_CYGWIN
55#include <private/qlocale_tools_p.h>
56
57#include <qmutex.h>
58#include <QtCore/private/qlocking_p.h>
59
60#include <stdlib.h>
61#include <limits.h>
62#include <stdarg.h>
63#include <string.h>
64
65#ifndef QT_NO_EXCEPTIONS
66# include <string>
67# include <exception>
68#endif
69
70#include <errno.h>
71#if defined(Q_CC_MSVC)
72# include <crtdbg.h>
73#endif
74
75#ifdef Q_OS_WINRT
76#include <Ws2tcpip.h>
77#endif // Q_OS_WINRT
78
79#ifdef Q_OS_WIN
80# include <qt_windows.h>
81#endif
82
83#if defined(Q_OS_VXWORKS) && defined(_WRS_KERNEL)
84# include <envLib.h>
85#endif
86
87#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
88#include <private/qjni_p.h>
89#endif
90
91#if defined(Q_OS_SOLARIS)
92# include <sys/systeminfo.h>
93#endif
94
95#if defined(Q_OS_DARWIN) && __has_include(<IOKit/IOKitLib.h>)
96# include <IOKit/IOKitLib.h>
97# include <private/qcore_mac_p.h>
98#endif
99
100#ifdef Q_OS_UNIX
101#include <sys/utsname.h>
102#include <private/qcore_unix_p.h>
103#endif
104
105#ifdef Q_OS_BSD4
106#include <sys/sysctl.h>
107#endif
108
109#if defined(Q_OS_INTEGRITY)
110extern "C" {
111 // Function mmap resides in libshm_client.a. To be able to link with it one needs
112 // to define symbols 'shm_area_password' and 'shm_area_name', because the library
113 // is meant to allow the application that links to it to use POSIX shared memory
114 // without full system POSIX.
115# pragma weak shm_area_password
116# pragma weak shm_area_name
117 char shm_area_password[] = "dummy";
118 char shm_area_name[] = "dummy";
119}
120#endif
121
122#include "archdetect.cpp"
123
124#ifdef qFatal
125// the qFatal in this file are just redirections from elsewhere, so
126// don't capture any context again
127# undef qFatal
128#endif
129
130QT_BEGIN_NAMESPACE
131
132#if !QT_DEPRECATED_SINCE(5, 0)
133// Make sure they're defined to be exported
134Q_CORE_EXPORT void *qMemCopy(void *dest, const void *src, size_t n);
135Q_CORE_EXPORT void *qMemSet(void *dest, int c, size_t n);
136#endif
137
138// Statically check assumptions about the environment we're running
139// in. The idea here is to error or warn if otherwise implicit Qt
140// assumptions are not fulfilled on new hardware or compilers
141// (if this list becomes too long, consider factoring into a separate file)
142Q_STATIC_ASSERT_X(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
143Q_STATIC_ASSERT_X(sizeof(int) == 4, "Qt assumes that int is 32 bits");
144Q_STATIC_ASSERT_X(QT_POINTER_SIZE == sizeof(void *), "QT_POINTER_SIZE defined incorrectly");
145Q_STATIC_ASSERT_X(sizeof(float) == 4, "Qt assumes that float is 32 bits");
146Q_STATIC_ASSERT_X(sizeof(char16_t) == 2, "Qt assumes that char16_t is 16 bits");
147Q_STATIC_ASSERT_X(sizeof(char32_t) == 4, "Qt assumes that char32_t is 32 bits");
148Q_STATIC_ASSERT_X(std::numeric_limits<int>::radix == 2,
149 "Qt assumes binary integers");
150Q_STATIC_ASSERT_X((std::numeric_limits<int>::max() + std::numeric_limits<int>::lowest()) == -1,
151 "Qt assumes two's complement integers");
152
153// While we'd like to check for __STDC_IEC_559__, as per ISO/IEC 9899:2011
154// Annex F (C11, normative for C++11), there are a few corner cases regarding
155// denormals where GHS compiler is relying hardware behavior that is not IEC
156// 559 compliant. So split the check in several subchecks.
157
158// On GHC the compiler reports std::numeric_limits<float>::is_iec559 as false.
159// This is all right according to our needs.
160#if !defined(Q_CC_GHS)
161Q_STATIC_ASSERT_X(std::numeric_limits<float>::is_iec559,
162 "Qt assumes IEEE 754 floating point");
163#endif
164
165// Technically, presence of NaN and infinities are implied from the above check,
166// but double checking our environment doesn't hurt...
167Q_STATIC_ASSERT_X(std::numeric_limits<float>::has_infinity &&
168 std::numeric_limits<float>::has_quiet_NaN &&
169 std::numeric_limits<float>::has_signaling_NaN,
170 "Qt assumes IEEE 754 floating point");
171
172// is_iec559 checks for ISO/IEC/IEEE 60559:2011 (aka IEEE 754-2008) compliance,
173// but that allows for a non-binary radix. We need to recheck that.
174// Note how __STDC_IEC_559__ would instead check for IEC 60559:1989, aka
175// ANSI/IEEE 754−1985, which specifically implies binary floating point numbers.
176Q_STATIC_ASSERT_X(std::numeric_limits<float>::radix == 2,
177 "Qt assumes binary IEEE 754 floating point");
178
179// not required by the definition of size_t, but we depend on this
180Q_STATIC_ASSERT_X(sizeof(size_t) == sizeof(void *), "size_t and a pointer don't have the same size");
181Q_STATIC_ASSERT(sizeof(size_t) == sizeof(qsizetype)); // implied by the definition
182Q_STATIC_ASSERT((std::is_same<qsizetype, qptrdiff>::value));
183
184/*!
185 \class QFlag
186 \inmodule QtCore
187 \brief The QFlag class is a helper data type for QFlags.
188
189 It is equivalent to a plain \c int, except with respect to
190 function overloading and type conversions. You should never need
191 to use this class in your applications.
192
193 \sa QFlags
194*/
195
196/*!
197 \fn QFlag::QFlag(int value)
198
199 Constructs a QFlag object that stores the \a value.
200*/
201
202/*!
203 \fn QFlag::QFlag(uint value)
204 \since 5.3
205
206 Constructs a QFlag object that stores the \a value.
207*/
208
209/*!
210 \fn QFlag::QFlag(short value)
211 \since 5.3
212
213 Constructs a QFlag object that stores the \a value.
214*/
215
216/*!
217 \fn QFlag::QFlag(ushort value)
218 \since 5.3
219
220 Constructs a QFlag object that stores the \a value.
221*/
222
223/*!
224 \fn QFlag::operator int() const
225
226 Returns the value stored by the QFlag object.
227*/
228
229/*!
230 \fn QFlag::operator uint() const
231 \since 5.3
232
233 Returns the value stored by the QFlag object.
234*/
235
236/*!
237 \class QFlags
238 \inmodule QtCore
239 \brief The QFlags class provides a type-safe way of storing
240 OR-combinations of enum values.
241
242
243 \ingroup tools
244
245 The QFlags<Enum> class is a template class, where Enum is an enum
246 type. QFlags is used throughout Qt for storing combinations of
247 enum values.
248
249 The traditional C++ approach for storing OR-combinations of enum
250 values is to use an \c int or \c uint variable. The inconvenience
251 with this approach is that there's no type checking at all; any
252 enum value can be OR'd with any other enum value and passed on to
253 a function that takes an \c int or \c uint.
254
255 Qt uses QFlags to provide type safety. For example, the
256 Qt::Alignment type is simply a typedef for
257 QFlags<Qt::AlignmentFlag>. QLabel::setAlignment() takes a
258 Qt::Alignment parameter, which means that any combination of
259 Qt::AlignmentFlag values, or \c{{ }}, is legal:
260
261 \snippet code/src_corelib_global_qglobal.cpp 0
262
263 If you try to pass a value from another enum or just a plain
264 integer other than 0, the compiler will report an error. If you
265 need to cast integer values to flags in a untyped fashion, you can
266 use the explicit QFlags constructor as cast operator.
267
268 If you want to use QFlags for your own enum types, use
269 the Q_DECLARE_FLAGS() and Q_DECLARE_OPERATORS_FOR_FLAGS().
270
271 Example:
272
273 \snippet code/src_corelib_global_qglobal.cpp 1
274
275 You can then use the \c MyClass::Options type to store
276 combinations of \c MyClass::Option values.
277
278 \section1 Flags and the Meta-Object System
279
280 The Q_DECLARE_FLAGS() macro does not expose the flags to the meta-object
281 system, so they cannot be used by Qt Script or edited in Qt Designer.
282 To make the flags available for these purposes, the Q_FLAG() macro must
283 be used:
284
285 \snippet code/src_corelib_global_qglobal.cpp meta-object flags
286
287 \section1 Naming Convention
288
289 A sensible naming convention for enum types and associated QFlags
290 types is to give a singular name to the enum type (e.g., \c
291 Option) and a plural name to the QFlags type (e.g., \c Options).
292 When a singular name is desired for the QFlags type (e.g., \c
293 Alignment), you can use \c Flag as the suffix for the enum type
294 (e.g., \c AlignmentFlag).
295
296 \sa QFlag
297*/
298
299/*!
300 \typedef QFlags::Int
301 \since 5.0
302
303 Typedef for the integer type used for storage as well as for
304 implicit conversion. Either \c int or \c{unsigned int}, depending
305 on whether the enum's underlying type is signed or unsigned.
306*/
307
308/*!
309 \typedef QFlags::enum_type
310
311 Typedef for the Enum template type.
312*/
313
314/*!
315 \fn template<typename Enum> QFlags<Enum>::QFlags(const QFlags &other)
316
317 Constructs a copy of \a other.
318*/
319
320/*!
321 \fn template <typename Enum> QFlags<Enum>::QFlags(Enum flags)
322
323 Constructs a QFlags object storing the \a flags.
324*/
325
326/*!
327 \fn template <typename Enum> QFlags<Enum>::QFlags()
328 \since 5.15
329
330 Constructs a QFlags object with no flags set.
331*/
332
333/*!
334 \fn template <typename Enum> QFlags<Enum>::QFlags(Zero)
335 \deprecated
336
337 Constructs a QFlags object with no flags set. The parameter must be a
338 literal 0 value.
339
340 Deprecated, use default constructor instead.
341*/
342
343/*!
344 \fn template <typename Enum> QFlags<Enum>::QFlags(QFlag flag)
345
346 Constructs a QFlags object initialized with the integer \a flag.
347
348 The QFlag type is a helper type. By using it here instead of \c
349 int, we effectively ensure that arbitrary enum values cannot be
350 cast to a QFlags, whereas untyped enum values (i.e., \c int
351 values) can.
352*/
353
354/*!
355 \fn template <typename Enum> QFlags<Enum>::QFlags(std::initializer_list<Enum> flags)
356 \since 5.4
357
358 Constructs a QFlags object initialized with all \a flags
359 combined using the bitwise OR operator.
360
361 \sa operator|=(), operator|()
362*/
363
364/*!
365 \fn template <typename Enum> QFlags &QFlags<Enum>::operator=(const QFlags &other)
366
367 Assigns \a other to this object and returns a reference to this
368 object.
369*/
370
371/*!
372 \fn template <typename Enum> QFlags &QFlags<Enum>::operator&=(int mask)
373
374 Performs a bitwise AND operation with \a mask and stores the
375 result in this QFlags object. Returns a reference to this object.
376
377 \sa operator&(), operator|=(), operator^=()
378*/
379
380/*!
381 \fn template <typename Enum> QFlags &QFlags<Enum>::operator&=(uint mask)
382
383 \overload
384*/
385
386/*!
387 \fn template <typename Enum> QFlags &QFlags<Enum>::operator&=(Enum mask)
388
389 \overload
390*/
391
392/*!
393 \fn template <typename Enum> QFlags &QFlags<Enum>::operator|=(QFlags other)
394
395 Performs a bitwise OR operation with \a other and stores the
396 result in this QFlags object. Returns a reference to this object.
397
398 \sa operator|(), operator&=(), operator^=()
399*/
400
401/*!
402 \fn template <typename Enum> QFlags &QFlags<Enum>::operator|=(Enum other)
403
404 \overload
405*/
406
407/*!
408 \fn template <typename Enum> QFlags &QFlags<Enum>::operator^=(QFlags other)
409
410 Performs a bitwise XOR operation with \a other and stores the
411 result in this QFlags object. Returns a reference to this object.
412
413 \sa operator^(), operator&=(), operator|=()
414*/
415
416/*!
417 \fn template <typename Enum> QFlags &QFlags<Enum>::operator^=(Enum other)
418
419 \overload
420*/
421
422/*!
423 \fn template <typename Enum> QFlags<Enum>::operator Int() const
424
425 Returns the value stored in the QFlags object as an integer.
426
427 \sa Int
428*/
429
430/*!
431 \fn template <typename Enum> QFlags QFlags<Enum>::operator|(QFlags other) const
432
433 Returns a QFlags object containing the result of the bitwise OR
434 operation on this object and \a other.
435
436 \sa operator|=(), operator^(), operator&(), operator~()
437*/
438
439/*!
440 \fn template <typename Enum> QFlags QFlags<Enum>::operator|(Enum other) const
441
442 \overload
443*/
444
445/*!
446 \fn template <typename Enum> QFlags QFlags<Enum>::operator^(QFlags other) const
447
448 Returns a QFlags object containing the result of the bitwise XOR
449 operation on this object and \a other.
450
451 \sa operator^=(), operator&(), operator|(), operator~()
452*/
453
454/*!
455 \fn template <typename Enum> QFlags QFlags<Enum>::operator^(Enum other) const
456
457 \overload
458*/
459
460/*!
461 \fn template <typename Enum> QFlags QFlags<Enum>::operator&(int mask) const
462
463 Returns a QFlags object containing the result of the bitwise AND
464 operation on this object and \a mask.
465
466 \sa operator&=(), operator|(), operator^(), operator~()
467*/
468
469/*!
470 \fn template <typename Enum> QFlags QFlags<Enum>::operator&(uint mask) const
471
472 \overload
473*/
474
475/*!
476 \fn template <typename Enum> QFlags QFlags<Enum>::operator&(Enum mask) const
477
478 \overload
479*/
480
481/*!
482 \fn template <typename Enum> QFlags QFlags<Enum>::operator~() const
483
484 Returns a QFlags object that contains the bitwise negation of
485 this object.
486
487 \sa operator&(), operator|(), operator^()
488*/
489
490/*!
491 \fn template <typename Enum> bool QFlags<Enum>::operator!() const
492
493 Returns \c true if no flag is set (i.e., if the value stored by the
494 QFlags object is 0); otherwise returns \c false.
495*/
496
497/*!
498 \fn template <typename Enum> bool QFlags<Enum>::testFlag(Enum flag) const
499 \since 4.2
500
501 Returns \c true if the flag \a flag is set, otherwise \c false.
502
503 \note if \a flag contains multiple bits set to 1 (for instance, if
504 it's an enumerator equal to the bitwise-OR of other enumerators)
505 then this function will return \c true if and only if all the bits
506 are set in this flags object. On the other hand, if \a flag contains
507 no bits set to 1 (that is, its value as a integer is 0), then this
508 function will return \c true if and only if this flags object also
509 has no bits set to 1.
510*/
511
512/*!
513 \fn template <typename Enum> QFlags QFlags<Enum>::setFlag(Enum flag, bool on)
514 \since 5.7
515
516 Sets the flag \a flag if \a on is \c true or unsets it if
517 \a on is \c false. Returns a reference to this object.
518*/
519
520/*!
521 \macro Q_DISABLE_COPY(Class)
522 \relates QObject
523
524 Disables the use of copy constructors and assignment operators
525 for the given \a Class.
526
527 Instances of subclasses of QObject should not be thought of as
528 values that can be copied or assigned, but as unique identities.
529 This means that when you create your own subclass of QObject
530 (director or indirect), you should \e not give it a copy constructor
531 or an assignment operator. However, it may not enough to simply
532 omit them from your class, because, if you mistakenly write some code
533 that requires a copy constructor or an assignment operator (it's easy
534 to do), your compiler will thoughtfully create it for you. You must
535 do more.
536
537 The curious user will have seen that the Qt classes derived
538 from QObject typically include this macro in a private section:
539
540 \snippet code/src_corelib_global_qglobal.cpp 43
541
542 It declares a copy constructor and an assignment operator in the
543 private section, so that if you use them by mistake, the compiler
544 will report an error.
545
546 \snippet code/src_corelib_global_qglobal.cpp 44
547
548 But even this might not catch absolutely every case. You might be
549 tempted to do something like this:
550
551 \snippet code/src_corelib_global_qglobal.cpp 45
552
553 First of all, don't do that. Most compilers will generate code that
554 uses the copy constructor, so the privacy violation error will be
555 reported, but your C++ compiler is not required to generate code for
556 this statement in a specific way. It could generate code using
557 \e{neither} the copy constructor \e{nor} the assignment operator we
558 made private. In that case, no error would be reported, but your
559 application would probably crash when you called a member function
560 of \c{w}.
561
562 \sa Q_DISABLE_COPY_MOVE, Q_DISABLE_MOVE
563*/
564
565/*!
566 \macro Q_DISABLE_MOVE(Class)
567 \relates QObject
568
569 Disables the use of move constructors and move assignment operators
570 for the given \a Class.
571
572 \sa Q_DISABLE_COPY, Q_DISABLE_COPY_MOVE
573 \since 5.13
574*/
575
576/*!
577 \macro Q_DISABLE_COPY_MOVE(Class)
578 \relates QObject
579
580 A convenience macro that disables the use of copy constructors, assignment
581 operators, move constructors and move assignment operators for the given
582 \a Class, combining Q_DISABLE_COPY and Q_DISABLE_MOVE.
583
584 \sa Q_DISABLE_COPY, Q_DISABLE_MOVE
585 \since 5.13
586*/
587
588/*!
589 \macro Q_DECLARE_FLAGS(Flags, Enum)
590 \relates QFlags
591
592 The Q_DECLARE_FLAGS() macro expands to
593
594 \snippet code/src_corelib_global_qglobal.cpp 2
595
596 \a Enum is the name of an existing enum type, whereas \a Flags is
597 the name of the QFlags<\e{Enum}> typedef.
598
599 See the QFlags documentation for details.
600
601 \sa Q_DECLARE_OPERATORS_FOR_FLAGS()
602*/
603
604/*!
605 \macro Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
606 \relates QFlags
607
608 The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global \c
609 operator|() functions for \a Flags, which is of type QFlags<T>.
610
611 See the QFlags documentation for details.
612
613 \sa Q_DECLARE_FLAGS()
614*/
615
616/*!
617 \headerfile <QtGlobal>
618 \title Global Qt Declarations
619 \ingroup funclists
620
621 \brief The <QtGlobal> header file includes the fundamental global
622 declarations. It is included by most other Qt header files.
623
624 The global declarations include \l{types}, \l{functions} and
625 \l{macros}.
626
627 The type definitions are partly convenience definitions for basic
628 types (some of which guarantee certain bit-sizes on all platforms
629 supported by Qt), partly types related to Qt message handling. The
630 functions are related to generating messages, Qt version handling
631 and comparing and adjusting object values. And finally, some of
632 the declared macros enable programmers to add compiler or platform
633 specific code to their applications, while others are convenience
634 macros for larger operations.
635
636 \section1 Types
637
638 The header file declares several type definitions that guarantee a
639 specified bit-size on all platforms supported by Qt for various
640 basic types, for example \l qint8 which is a signed char
641 guaranteed to be 8-bit on all platforms supported by Qt. The
642 header file also declares the \l qlonglong type definition for \c
643 {long long int } (\c __int64 on Windows).
644
645 Several convenience type definitions are declared: \l qreal for \c
646 double or \c float, \l uchar for \c unsigned char, \l uint for \c unsigned
647 int, \l ulong for \c unsigned long and \l ushort for \c unsigned
648 short.
649
650 Finally, the QtMsgType definition identifies the various messages
651 that can be generated and sent to a Qt message handler;
652 QtMessageHandler is a type definition for a pointer to a function with
653 the signature
654 \c {void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *)}.
655 QMessageLogContext class contains the line, file, and function the
656 message was logged at. This information is created by the QMessageLogger
657 class.
658
659 \section1 Functions
660
661 The <QtGlobal> header file contains several functions comparing
662 and adjusting an object's value. These functions take a template
663 type as argument: You can retrieve the absolute value of an object
664 using the qAbs() function, and you can bound a given object's
665 value by given minimum and maximum values using the qBound()
666 function. You can retrieve the minimum and maximum of two given
667 objects using qMin() and qMax() respectively. All these functions
668 return a corresponding template type; the template types can be
669 replaced by any other type.
670
671 Example:
672
673 \snippet code/src_corelib_global_qglobal.cpp 3
674
675 <QtGlobal> also contains functions that generate messages from the
676 given string argument: qDebug(), qInfo(), qWarning(), qCritical(),
677 and qFatal(). These functions call the message handler
678 with the given message.
679
680 Example:
681
682 \snippet code/src_corelib_global_qglobal.cpp 4
683
684 The remaining functions are qRound() and qRound64(), which both
685 accept a \c double or \c float value as their argument returning
686 the value rounded up to the nearest integer and 64-bit integer
687 respectively, the qInstallMessageHandler() function which installs
688 the given QtMessageHandler, and the qVersion() function which
689 returns the version number of Qt at run-time as a string.
690
691 \section1 Macros
692
693 The <QtGlobal> header file provides a range of macros (Q_CC_*)
694 that are defined if the application is compiled using the
695 specified platforms. For example, the Q_CC_SUN macro is defined if
696 the application is compiled using Forte Developer, or Sun Studio
697 C++. The header file also declares a range of macros (Q_OS_*)
698 that are defined for the specified platforms. For example,
699 Q_OS_UNIX which is defined for the Unix-based systems.
700
701 The purpose of these macros is to enable programmers to add
702 compiler or platform specific code to their application.
703
704 The remaining macros are convenience macros for larger operations:
705 The QT_TR_NOOP(), QT_TRANSLATE_NOOP(), and QT_TRANSLATE_NOOP3()
706 macros provide the possibility of marking strings for delayed
707 translation. QT_TR_N_NOOP(), QT_TRANSLATE_N_NOOP(), and
708 QT_TRANSLATE_N_NOOP3() are numerator dependent variants of these.
709 The Q_ASSERT() and Q_ASSERT_X() enables warning messages of various
710 level of refinement. The Q_FOREACH() and foreach() macros
711 implement Qt's foreach loop.
712
713 The Q_INT64_C() and Q_UINT64_C() macros wrap signed and unsigned
714 64-bit integer literals in a platform-independent way. The
715 Q_CHECK_PTR() macro prints a warning containing the source code's
716 file name and line number, saying that the program ran out of
717 memory, if the pointer is \nullptr. The qPrintable() and qUtf8Printable()
718 macros represent an easy way of printing text.
719
720 The QT_POINTER_SIZE macro expands to the size of a pointer in bytes.
721
722 The macros QT_VERSION and QT_VERSION_STR expand to a numeric value
723 or a string, respectively, that specifies the version of Qt that the
724 application is compiled against.
725
726 \sa <QtAlgorithms>, QSysInfo
727*/
728
729/*!
730 \typedef qreal
731 \relates <QtGlobal>
732
733 Typedef for \c double unless Qt is configured with the
734 \c{-qreal float} option.
735*/
736
737/*! \typedef uchar
738 \relates <QtGlobal>
739
740 Convenience typedef for \c{unsigned char}.
741*/
742
743/*! \typedef ushort
744 \relates <QtGlobal>
745
746 Convenience typedef for \c{unsigned short}.
747*/
748
749/*! \typedef uint
750 \relates <QtGlobal>
751
752 Convenience typedef for \c{unsigned int}.
753*/
754
755/*! \typedef ulong
756 \relates <QtGlobal>
757
758 Convenience typedef for \c{unsigned long}.
759*/
760
761/*! \typedef qint8
762 \relates <QtGlobal>
763
764 Typedef for \c{signed char}. This type is guaranteed to be 8-bit
765 on all platforms supported by Qt.
766*/
767
768/*!
769 \typedef quint8
770 \relates <QtGlobal>
771
772 Typedef for \c{unsigned char}. This type is guaranteed to
773 be 8-bit on all platforms supported by Qt.
774*/
775
776/*! \typedef qint16
777 \relates <QtGlobal>
778
779 Typedef for \c{signed short}. This type is guaranteed to be
780 16-bit on all platforms supported by Qt.
781*/
782
783/*!
784 \typedef quint16
785 \relates <QtGlobal>
786
787 Typedef for \c{unsigned short}. This type is guaranteed to
788 be 16-bit on all platforms supported by Qt.
789*/
790
791/*! \typedef qint32
792 \relates <QtGlobal>
793
794 Typedef for \c{signed int}. This type is guaranteed to be 32-bit
795 on all platforms supported by Qt.
796*/
797
798/*!
799 \typedef quint32
800 \relates <QtGlobal>
801
802 Typedef for \c{unsigned int}. This type is guaranteed to
803 be 32-bit on all platforms supported by Qt.
804*/
805
806/*! \typedef qint64
807 \relates <QtGlobal>
808
809 Typedef for \c{long long int} (\c __int64 on Windows). This type
810 is guaranteed to be 64-bit on all platforms supported by Qt.
811
812 Literals of this type can be created using the Q_INT64_C() macro:
813
814 \snippet code/src_corelib_global_qglobal.cpp 5
815
816 \sa Q_INT64_C(), quint64, qlonglong
817*/
818
819/*!
820 \typedef quint64
821 \relates <QtGlobal>
822
823 Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
824 Windows). This type is guaranteed to be 64-bit on all platforms
825 supported by Qt.
826
827 Literals of this type can be created using the Q_UINT64_C()
828 macro:
829
830 \snippet code/src_corelib_global_qglobal.cpp 6
831
832 \sa Q_UINT64_C(), qint64, qulonglong
833*/
834
835/*!
836 \typedef qintptr
837 \relates <QtGlobal>
838
839 Integral type for representing pointers in a signed integer (useful for
840 hashing, etc.).
841
842 Typedef for either qint32 or qint64. This type is guaranteed to
843 be the same size as a pointer on all platforms supported by Qt. On
844 a system with 32-bit pointers, qintptr is a typedef for qint32;
845 on a system with 64-bit pointers, qintptr is a typedef for
846 qint64.
847
848 Note that qintptr is signed. Use quintptr for unsigned values.
849
850 \sa qptrdiff, qint32, qint64
851*/
852
853/*!
854 \typedef quintptr
855 \relates <QtGlobal>
856
857 Integral type for representing pointers in an unsigned integer (useful for
858 hashing, etc.).
859
860 Typedef for either quint32 or quint64. This type is guaranteed to
861 be the same size as a pointer on all platforms supported by Qt. On
862 a system with 32-bit pointers, quintptr is a typedef for quint32;
863 on a system with 64-bit pointers, quintptr is a typedef for
864 quint64.
865
866 Note that quintptr is unsigned. Use qptrdiff for signed values.
867
868 \sa qptrdiff, quint32, quint64
869*/
870
871/*!
872 \typedef qptrdiff
873 \relates <QtGlobal>
874
875 Integral type for representing pointer differences.
876
877 Typedef for either qint32 or qint64. This type is guaranteed to be
878 the same size as a pointer on all platforms supported by Qt. On a
879 system with 32-bit pointers, quintptr is a typedef for quint32; on
880 a system with 64-bit pointers, quintptr is a typedef for quint64.
881
882 Note that qptrdiff is signed. Use quintptr for unsigned values.
883
884 \sa quintptr, qint32, qint64
885*/
886
887/*!
888 \typedef qsizetype
889 \relates <QtGlobal>
890 \since 5.10
891
892 Integral type providing Posix' \c ssize_t for all platforms.
893
894 This type is guaranteed to be the same size as a \c size_t on all
895 platforms supported by Qt.
896
897 Note that qsizetype is signed. Use \c size_t for unsigned values.
898
899 \sa qptrdiff
900*/
901
902/*!
903 \enum QtMsgType
904 \relates <QtGlobal>
905
906 This enum describes the messages that can be sent to a message
907 handler (QtMessageHandler). You can use the enum to identify and
908 associate the various message types with the appropriate
909 actions.
910
911 \value QtDebugMsg
912 A message generated by the qDebug() function.
913 \value QtInfoMsg
914 A message generated by the qInfo() function.
915 \value QtWarningMsg
916 A message generated by the qWarning() function.
917 \value QtCriticalMsg
918 A message generated by the qCritical() function.
919 \value QtFatalMsg
920 A message generated by the qFatal() function.
921 \value QtSystemMsg
922
923 \c QtInfoMsg was added in Qt 5.5.
924
925 \sa QtMessageHandler, qInstallMessageHandler()
926*/
927
928/*! \typedef QFunctionPointer
929 \relates <QtGlobal>
930
931 This is a typedef for \c{void (*)()}, a pointer to a function that takes
932 no arguments and returns void.
933*/
934
935/*! \macro qint64 Q_INT64_C(literal)
936 \relates <QtGlobal>
937
938 Wraps the signed 64-bit integer \a literal in a
939 platform-independent way.
940
941 Example:
942
943 \snippet code/src_corelib_global_qglobal.cpp 8
944
945 \sa qint64, Q_UINT64_C()
946*/
947
948/*! \macro quint64 Q_UINT64_C(literal)
949 \relates <QtGlobal>
950
951 Wraps the unsigned 64-bit integer \a literal in a
952 platform-independent way.
953
954 Example:
955
956 \snippet code/src_corelib_global_qglobal.cpp 9
957
958 \sa quint64, Q_INT64_C()
959*/
960
961/*! \typedef qlonglong
962 \relates <QtGlobal>
963
964 Typedef for \c{long long int} (\c __int64 on Windows). This is
965 the same as \l qint64.
966
967 \sa qulonglong, qint64
968*/
969
970/*!
971 \typedef qulonglong
972 \relates <QtGlobal>
973
974 Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
975 Windows). This is the same as \l quint64.
976
977 \sa quint64, qlonglong
978*/
979
980/*! \fn template <typename T> T qAbs(const T &t)
981 \relates <QtGlobal>
982
983 Compares \a t to the 0 of type T and returns the absolute
984 value. Thus if T is \e {double}, then \a t is compared to
985 \e{(double) 0}.
986
987 Example:
988
989 \snippet code/src_corelib_global_qglobal.cpp 10
990*/
991
992/*! \fn int qRound(double d)
993 \relates <QtGlobal>
994
995 Rounds \a d to the nearest integer.
996
997 Rounds half up (e.g. 0.5 -> 1, -0.5 -> 0).
998
999 Example:
1000
1001 \snippet code/src_corelib_global_qglobal.cpp 11A
1002*/
1003
1004/*! \fn int qRound(float d)
1005 \relates <QtGlobal>
1006
1007 Rounds \a d to the nearest integer.
1008
1009 Rounds half up (e.g. 0.5f -> 1, -0.5f -> 0).
1010
1011 Example:
1012
1013 \snippet code/src_corelib_global_qglobal.cpp 11B
1014*/
1015
1016/*! \fn qint64 qRound64(double d)
1017 \relates <QtGlobal>
1018
1019 Rounds \a d to the nearest 64-bit integer.
1020
1021 Rounds half up (e.g. 0.5 -> 1, -0.5 -> 0).
1022
1023 Example:
1024
1025 \snippet code/src_corelib_global_qglobal.cpp 12A
1026*/
1027
1028/*! \fn qint64 qRound64(float d)
1029 \relates <QtGlobal>
1030
1031 Rounds \a d to the nearest 64-bit integer.
1032
1033 Rounds half up (e.g. 0.5f -> 1, -0.5f -> 0).
1034
1035 Example:
1036
1037 \snippet code/src_corelib_global_qglobal.cpp 12B
1038*/
1039
1040/*! \fn template <typename T> const T &qMin(const T &a, const T &b)
1041 \relates <QtGlobal>
1042
1043 Returns the minimum of \a a and \a b.
1044
1045 Example:
1046
1047 \snippet code/src_corelib_global_qglobal.cpp 13
1048
1049 \sa qMax(), qBound()
1050*/
1051
1052/*! \fn template <typename T> const T &qMax(const T &a, const T &b)
1053 \relates <QtGlobal>
1054
1055 Returns the maximum of \a a and \a b.
1056
1057 Example:
1058
1059 \snippet code/src_corelib_global_qglobal.cpp 14
1060
1061 \sa qMin(), qBound()
1062*/
1063
1064/*! \fn template <typename T> const T &qBound(const T &min, const T &val, const T &max)
1065 \relates <QtGlobal>
1066
1067 Returns \a val bounded by \a min and \a max. This is equivalent
1068 to qMax(\a min, qMin(\a val, \a max)).
1069
1070 Example:
1071
1072 \snippet code/src_corelib_global_qglobal.cpp 15
1073
1074 \sa qMin(), qMax()
1075*/
1076
1077/*! \fn template <typename T> auto qOverload(T functionPointer)
1078 \relates <QtGlobal>
1079 \since 5.7
1080
1081 Returns a pointer to an overloaded function. The template
1082 parameter is the list of the argument types of the function.
1083 \a functionPointer is the pointer to the (member) function:
1084
1085 \snippet code/src_corelib_global_qglobal.cpp 52
1086
1087 If a member function is also const-overloaded \l qConstOverload and
1088 \l qNonConstOverload need to be used.
1089
1090 qOverload() requires C++14 enabled. In C++11-only code, the helper
1091 classes QOverload, QConstOverload, and QNonConstOverload can be used directly:
1092
1093 \snippet code/src_corelib_global_qglobal.cpp 53
1094
1095 \note Qt detects the necessary C++14 compiler support by way of the feature
1096 test recommendations from
1097 \l{https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations}
1098 {C++ Committee's Standing Document 6}.
1099
1100 \sa qConstOverload(), qNonConstOverload(), {Differences between String-Based
1101 and Functor-Based Connections}
1102*/
1103
1104/*! \fn template <typename T> auto qConstOverload(T memberFunctionPointer)
1105 \relates <QtGlobal>
1106 \since 5.7
1107
1108 Returns the \a memberFunctionPointer pointer to a constant member function:
1109
1110 \snippet code/src_corelib_global_qglobal.cpp 54
1111
1112 \sa qOverload, qNonConstOverload, {Differences between String-Based
1113 and Functor-Based Connections}
1114*/
1115
1116/*! \fn template <typename T> auto qNonConstOverload(T memberFunctionPointer)
1117 \relates <QtGlobal>
1118 \since 5.7
1119
1120 Returns the \a memberFunctionPointer pointer to a non-constant member function:
1121
1122 \snippet code/src_corelib_global_qglobal.cpp 54
1123
1124 \sa qOverload, qNonConstOverload, {Differences between String-Based
1125 and Functor-Based Connections}
1126*/
1127
1128/*!
1129 \macro QT_VERSION_CHECK
1130 \relates <QtGlobal>
1131
1132 Turns the major, minor and patch numbers of a version into an
1133 integer, 0xMMNNPP (MM = major, NN = minor, PP = patch). This can
1134 be compared with another similarly processed version id.
1135
1136 Example:
1137
1138 \snippet code/src_corelib_global_qglobal.cpp qt-version-check
1139
1140 \sa QT_VERSION
1141*/
1142
1143/*!
1144 \macro QT_VERSION
1145 \relates <QtGlobal>
1146
1147 This macro expands a numeric value of the form 0xMMNNPP (MM =
1148 major, NN = minor, PP = patch) that specifies Qt's version
1149 number. For example, if you compile your application against Qt
1150 4.1.2, the QT_VERSION macro will expand to 0x040102.
1151
1152 You can use QT_VERSION to use the latest Qt features where
1153 available.
1154
1155 Example:
1156
1157 \snippet code/src_corelib_global_qglobal.cpp 16
1158
1159 \sa QT_VERSION_STR, qVersion()
1160*/
1161
1162/*!
1163 \macro QT_VERSION_STR
1164 \relates <QtGlobal>
1165
1166 This macro expands to a string that specifies Qt's version number
1167 (for example, "4.1.2"). This is the version against which the
1168 application is compiled.
1169
1170 \sa qVersion(), QT_VERSION
1171*/
1172
1173/*!
1174 \relates <QtGlobal>
1175
1176 Returns the version number of Qt at run-time as a string (for
1177 example, "4.1.2"). This may be a different version than the
1178 version the application was compiled against.
1179
1180 \sa QT_VERSION_STR, QLibraryInfo::version()
1181*/
1182
1183const char *qVersion() noexcept
1184{
1185 return QT_VERSION_STR;
1186}
1187
1188bool qSharedBuild() noexcept
1189{
1190#ifdef QT_SHARED
1191 return true;
1192#else
1193 return false;
1194#endif
1195}
1196
1197/*****************************************************************************
1198 System detection routines
1199 *****************************************************************************/
1200
1201/*!
1202 \class QSysInfo
1203 \inmodule QtCore
1204 \brief The QSysInfo class provides information about the system.
1205
1206 \list
1207 \li \l WordSize specifies the size of a pointer for the platform
1208 on which the application is compiled.
1209 \li \l ByteOrder specifies whether the platform is big-endian or
1210 little-endian.
1211 \endlist
1212
1213 Some constants are defined only on certain platforms. You can use
1214 the preprocessor symbols Q_OS_WIN and Q_OS_MACOS to test that
1215 the application is compiled under Windows or \macos.
1216
1217 \sa QLibraryInfo
1218*/
1219
1220/*!
1221 \enum QSysInfo::Sizes
1222
1223 This enum provides platform-specific information about the sizes of data
1224 structures used by the underlying architecture.
1225
1226 \value WordSize The size in bits of a pointer for the platform on which
1227 the application is compiled (32 or 64).
1228*/
1229
1230/*!
1231 \deprecated
1232 \variable QSysInfo::WindowsVersion
1233 \brief the version of the Windows operating system on which the
1234 application is run.
1235*/
1236
1237/*!
1238 \deprecated
1239 \fn QSysInfo::WindowsVersion QSysInfo::windowsVersion()
1240 \since 4.4
1241
1242 Returns the version of the Windows operating system on which the
1243 application is run, or WV_None if the operating system is not
1244 Windows.
1245*/
1246
1247/*!
1248 \deprecated
1249 \variable QSysInfo::MacintoshVersion
1250 \brief the version of the Macintosh operating system on which
1251 the application is run.
1252*/
1253
1254/*!
1255 \deprecated
1256 \fn QSysInfo::MacVersion QSysInfo::macVersion()
1257
1258 Returns the version of Darwin (\macos or iOS) on which the
1259 application is run, or MV_None if the operating system
1260 is not a version of Darwin.
1261*/
1262
1263/*!
1264 \enum QSysInfo::Endian
1265
1266 \value BigEndian Big-endian byte order (also called Network byte order)
1267 \value LittleEndian Little-endian byte order
1268 \value ByteOrder Equals BigEndian or LittleEndian, depending on
1269 the platform's byte order.
1270*/
1271
1272/*!
1273 \deprecated
1274 \enum QSysInfo::WinVersion
1275
1276 This enum provides symbolic names for the various versions of the
1277 Windows operating system. On Windows, the
1278 QSysInfo::WindowsVersion variable gives the version of the system
1279 on which the application is run.
1280
1281 MS-DOS-based versions:
1282
1283 \value WV_32s Windows 3.1 with Win 32s
1284 \value WV_95 Windows 95
1285 \value WV_98 Windows 98
1286 \value WV_Me Windows Me
1287
1288 NT-based versions (note that each operating system version is only represented once rather than each Windows edition):
1289
1290 \value WV_NT Windows NT (operating system version 4.0)
1291 \value WV_2000 Windows 2000 (operating system version 5.0)
1292 \value WV_XP Windows XP (operating system version 5.1)
1293 \value WV_2003 Windows Server 2003, Windows Server 2003 R2, Windows Home Server, Windows XP Professional x64 Edition (operating system version 5.2)
1294 \value WV_VISTA Windows Vista, Windows Server 2008 (operating system version 6.0)
1295 \value WV_WINDOWS7 Windows 7, Windows Server 2008 R2 (operating system version 6.1)
1296 \value WV_WINDOWS8 Windows 8 (operating system version 6.2)
1297 \value WV_WINDOWS8_1 Windows 8.1 (operating system version 6.3), introduced in Qt 5.2
1298 \value WV_WINDOWS10 Windows 10 (operating system version 10.0), introduced in Qt 5.5
1299
1300 Alternatively, you may use the following macros which correspond directly to the Windows operating system version number:
1301
1302 \value WV_4_0 Operating system version 4.0, corresponds to Windows NT
1303 \value WV_5_0 Operating system version 5.0, corresponds to Windows 2000
1304 \value WV_5_1 Operating system version 5.1, corresponds to Windows XP
1305 \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
1306 \value WV_6_0 Operating system version 6.0, corresponds to Windows Vista and Windows Server 2008
1307 \value WV_6_1 Operating system version 6.1, corresponds to Windows 7 and Windows Server 2008 R2
1308 \value WV_6_2 Operating system version 6.2, corresponds to Windows 8
1309 \value WV_6_3 Operating system version 6.3, corresponds to Windows 8.1, introduced in Qt 5.2
1310 \value WV_10_0 Operating system version 10.0, corresponds to Windows 10, introduced in Qt 5.5
1311
1312 The following masks can be used for testing whether a Windows
1313 version is MS-DOS-based or NT-based:
1314
1315 \value WV_DOS_based MS-DOS-based version of Windows
1316 \value WV_NT_based NT-based version of Windows
1317
1318 \value WV_None Operating system other than Windows.
1319
1320 \omitvalue WV_CE
1321 \omitvalue WV_CENET
1322 \omitvalue WV_CE_5
1323 \omitvalue WV_CE_6
1324 \omitvalue WV_CE_based
1325
1326 \sa MacVersion
1327*/
1328
1329/*!
1330 \deprecated
1331 \enum QSysInfo::MacVersion
1332
1333 This enum provides symbolic names for the various versions of the
1334 Darwin operating system, covering both \macos and iOS. The
1335 QSysInfo::MacintoshVersion variable gives the version of the
1336 system on which the application is run.
1337
1338 \value MV_9 \macos 9
1339 \value MV_10_0 \macos 10.0
1340 \value MV_10_1 \macos 10.1
1341 \value MV_10_2 \macos 10.2
1342 \value MV_10_3 \macos 10.3
1343 \value MV_10_4 \macos 10.4
1344 \value MV_10_5 \macos 10.5
1345 \value MV_10_6 \macos 10.6
1346 \value MV_10_7 \macos 10.7
1347 \value MV_10_8 \macos 10.8
1348 \value MV_10_9 \macos 10.9
1349 \value MV_10_10 \macos 10.10
1350 \value MV_10_11 \macos 10.11
1351 \value MV_10_12 \macos 10.12
1352 \value MV_Unknown An unknown and currently unsupported platform
1353
1354 \value MV_CHEETAH Apple codename for MV_10_0
1355 \value MV_PUMA Apple codename for MV_10_1
1356 \value MV_JAGUAR Apple codename for MV_10_2
1357 \value MV_PANTHER Apple codename for MV_10_3
1358 \value MV_TIGER Apple codename for MV_10_4
1359 \value MV_LEOPARD Apple codename for MV_10_5
1360 \value MV_SNOWLEOPARD Apple codename for MV_10_6
1361 \value MV_LION Apple codename for MV_10_7
1362 \value MV_MOUNTAINLION Apple codename for MV_10_8
1363 \value MV_MAVERICKS Apple codename for MV_10_9
1364 \value MV_YOSEMITE Apple codename for MV_10_10
1365 \value MV_ELCAPITAN Apple codename for MV_10_11
1366 \value MV_SIERRA Apple codename for MV_10_12
1367
1368 \value MV_IOS iOS (any)
1369 \value MV_IOS_4_3 iOS 4.3
1370 \value MV_IOS_5_0 iOS 5.0
1371 \value MV_IOS_5_1 iOS 5.1
1372 \value MV_IOS_6_0 iOS 6.0
1373 \value MV_IOS_6_1 iOS 6.1
1374 \value MV_IOS_7_0 iOS 7.0
1375 \value MV_IOS_7_1 iOS 7.1
1376 \value MV_IOS_8_0 iOS 8.0
1377 \value MV_IOS_8_1 iOS 8.1
1378 \value MV_IOS_8_2 iOS 8.2
1379 \value MV_IOS_8_3 iOS 8.3
1380 \value MV_IOS_8_4 iOS 8.4
1381 \value MV_IOS_9_0 iOS 9.0
1382 \value MV_IOS_9_1 iOS 9.1
1383 \value MV_IOS_9_2 iOS 9.2
1384 \value MV_IOS_9_3 iOS 9.3
1385 \value MV_IOS_10_0 iOS 10.0
1386
1387 \value MV_TVOS tvOS (any)
1388 \value MV_TVOS_9_0 tvOS 9.0
1389 \value MV_TVOS_9_1 tvOS 9.1
1390 \value MV_TVOS_9_2 tvOS 9.2
1391 \value MV_TVOS_10_0 tvOS 10.0
1392
1393 \value MV_WATCHOS watchOS (any)
1394 \value MV_WATCHOS_2_0 watchOS 2.0
1395 \value MV_WATCHOS_2_1 watchOS 2.1
1396 \value MV_WATCHOS_2_2 watchOS 2.2
1397 \value MV_WATCHOS_3_0 watchOS 3.0
1398
1399 \value MV_None Not a Darwin operating system
1400
1401 \sa WinVersion
1402*/
1403
1404/*!
1405 \macro Q_OS_DARWIN
1406 \relates <QtGlobal>
1407
1408 Defined on Darwin-based operating systems such as \macos, iOS, watchOS, and tvOS.
1409*/
1410
1411/*!
1412 \macro Q_OS_MAC
1413 \relates <QtGlobal>
1414
1415 Deprecated synonym for \c Q_OS_DARWIN. Do not use.
1416 */
1417
1418/*!
1419 \macro Q_OS_OSX
1420 \relates <QtGlobal>
1421
1422 Deprecated synonym for \c Q_OS_MACOS. Do not use.
1423 */
1424
1425/*!
1426 \macro Q_OS_MACOS
1427 \relates <QtGlobal>
1428
1429 Defined on \macos.
1430 */
1431
1432/*!
1433 \macro Q_OS_IOS
1434 \relates <QtGlobal>
1435
1436 Defined on iOS.
1437 */
1438
1439/*!
1440 \macro Q_OS_WATCHOS
1441 \relates <QtGlobal>
1442
1443 Defined on watchOS.
1444 */
1445
1446/*!
1447 \macro Q_OS_TVOS
1448 \relates <QtGlobal>
1449
1450 Defined on tvOS.
1451 */
1452
1453/*!
1454 \macro Q_OS_WIN
1455 \relates <QtGlobal>
1456
1457 Defined on all supported versions of Windows. That is, if
1458 \l Q_OS_WIN32, \l Q_OS_WIN64, or \l Q_OS_WINRT is defined.
1459*/
1460
1461/*!
1462 \macro Q_OS_WINDOWS
1463 \relates <QtGlobal>
1464
1465 This is a synonym for Q_OS_WIN.
1466*/
1467
1468/*!
1469 \macro Q_OS_WIN32
1470 \relates <QtGlobal>
1471
1472 Defined on 32-bit and 64-bit versions of Windows.
1473*/
1474
1475/*!
1476 \macro Q_OS_WIN64
1477 \relates <QtGlobal>
1478
1479 Defined on 64-bit versions of Windows.
1480*/
1481
1482/*!
1483 \macro Q_OS_WINRT
1484 \relates <QtGlobal>
1485
1486 Defined for Windows Runtime (Windows Store apps) on Windows 8, Windows RT,
1487 and Windows Phone 8.
1488*/
1489
1490/*!
1491 \macro Q_OS_CYGWIN
1492 \relates <QtGlobal>
1493
1494 Defined on Cygwin.
1495*/
1496
1497/*!
1498 \macro Q_OS_SOLARIS
1499 \relates <QtGlobal>
1500
1501 Defined on Sun Solaris.
1502*/
1503
1504/*!
1505 \macro Q_OS_HPUX
1506 \relates <QtGlobal>
1507
1508 Defined on HP-UX.
1509*/
1510
1511/*!
1512 \macro Q_OS_LINUX
1513 \relates <QtGlobal>
1514
1515 Defined on Linux.
1516*/
1517
1518/*!
1519 \macro Q_OS_ANDROID
1520 \relates <QtGlobal>
1521
1522 Defined on Android.
1523*/
1524
1525/*!
1526 \macro Q_OS_FREEBSD
1527 \relates <QtGlobal>
1528
1529 Defined on FreeBSD.
1530*/
1531
1532/*!
1533 \macro Q_OS_NETBSD
1534 \relates <QtGlobal>
1535
1536 Defined on NetBSD.
1537*/
1538
1539/*!
1540 \macro Q_OS_OPENBSD
1541 \relates <QtGlobal>
1542
1543 Defined on OpenBSD.
1544*/
1545
1546/*!
1547 \macro Q_OS_AIX
1548 \relates <QtGlobal>
1549
1550 Defined on AIX.
1551*/
1552
1553/*!
1554 \macro Q_OS_HURD
1555 \relates <QtGlobal>
1556
1557 Defined on GNU Hurd.
1558*/
1559
1560/*!
1561 \macro Q_OS_QNX
1562 \relates <QtGlobal>
1563
1564 Defined on QNX Neutrino.
1565*/
1566
1567/*!
1568 \macro Q_OS_LYNX
1569 \relates <QtGlobal>
1570
1571 Defined on LynxOS.
1572*/
1573
1574/*!
1575 \macro Q_OS_BSD4
1576 \relates <QtGlobal>
1577
1578 Defined on Any BSD 4.4 system.
1579*/
1580
1581/*!
1582 \macro Q_OS_UNIX
1583 \relates <QtGlobal>
1584
1585 Defined on Any UNIX BSD/SYSV system.
1586*/
1587
1588/*!
1589 \macro Q_OS_WASM
1590 \relates <QtGlobal>
1591
1592 Defined on Web Assembly.
1593*/
1594
1595/*!
1596 \macro Q_CC_SYM
1597 \relates <QtGlobal>
1598
1599 Defined if the application is compiled using Digital Mars C/C++
1600 (used to be Symantec C++).
1601*/
1602
1603/*!
1604 \macro Q_CC_MSVC
1605 \relates <QtGlobal>
1606
1607 Defined if the application is compiled using Microsoft Visual
1608 C/C++, Intel C++ for Windows.
1609*/
1610
1611/*!
1612 \macro Q_CC_CLANG
1613 \relates <QtGlobal>
1614
1615 Defined if the application is compiled using Clang.
1616*/
1617
1618/*!
1619 \macro Q_CC_BOR
1620 \relates <QtGlobal>
1621
1622 Defined if the application is compiled using Borland/Turbo C++.
1623*/
1624
1625/*!
1626 \macro Q_CC_WAT
1627 \relates <QtGlobal>
1628
1629 Defined if the application is compiled using Watcom C++.
1630*/
1631
1632/*!
1633 \macro Q_CC_GNU
1634 \relates <QtGlobal>
1635
1636 Defined if the application is compiled using GNU C++.
1637*/
1638
1639/*!
1640 \macro Q_CC_COMEAU
1641 \relates <QtGlobal>
1642
1643 Defined if the application is compiled using Comeau C++.
1644*/
1645
1646/*!
1647 \macro Q_CC_EDG
1648 \relates <QtGlobal>
1649
1650 Defined if the application is compiled using Edison Design Group
1651 C++.
1652*/
1653
1654/*!
1655 \macro Q_CC_OC
1656 \relates <QtGlobal>
1657
1658 Defined if the application is compiled using CenterLine C++.
1659*/
1660
1661/*!
1662 \macro Q_CC_SUN
1663 \relates <QtGlobal>
1664
1665 Defined if the application is compiled using Forte Developer, or
1666 Sun Studio C++.
1667*/
1668
1669/*!
1670 \macro Q_CC_MIPS
1671 \relates <QtGlobal>
1672
1673 Defined if the application is compiled using MIPSpro C++.
1674*/
1675
1676/*!
1677 \macro Q_CC_DEC
1678 \relates <QtGlobal>
1679
1680 Defined if the application is compiled using DEC C++.
1681*/
1682
1683/*!
1684 \macro Q_CC_HPACC
1685 \relates <QtGlobal>
1686
1687 Defined if the application is compiled using HP aC++.
1688*/
1689
1690/*!
1691 \macro Q_CC_USLC
1692 \relates <QtGlobal>
1693
1694 Defined if the application is compiled using SCO OUDK and UDK.
1695*/
1696
1697/*!
1698 \macro Q_CC_CDS
1699 \relates <QtGlobal>
1700
1701 Defined if the application is compiled using Reliant C++.
1702*/
1703
1704/*!
1705 \macro Q_CC_KAI
1706 \relates <QtGlobal>
1707
1708 Defined if the application is compiled using KAI C++.
1709*/
1710
1711/*!
1712 \macro Q_CC_INTEL
1713 \relates <QtGlobal>
1714
1715 Defined if the application is compiled using Intel C++ for Linux,
1716 Intel C++ for Windows.
1717*/
1718
1719/*!
1720 \macro Q_CC_HIGHC
1721 \relates <QtGlobal>
1722
1723 Defined if the application is compiled using MetaWare High C/C++.
1724*/
1725
1726/*!
1727 \macro Q_CC_PGI
1728 \relates <QtGlobal>
1729
1730 Defined if the application is compiled using Portland Group C++.
1731*/
1732
1733/*!
1734 \macro Q_CC_GHS
1735 \relates <QtGlobal>
1736
1737 Defined if the application is compiled using Green Hills
1738 Optimizing C++ Compilers.
1739*/
1740
1741/*!
1742 \macro Q_PROCESSOR_ALPHA
1743 \relates <QtGlobal>
1744
1745 Defined if the application is compiled for Alpha processors.
1746
1747 \sa QSysInfo::buildCpuArchitecture()
1748*/
1749
1750/*!
1751 \macro Q_PROCESSOR_ARM
1752 \relates <QtGlobal>
1753
1754 Defined if the application is compiled for ARM processors. Qt currently
1755 supports three optional ARM revisions: \l Q_PROCESSOR_ARM_V5, \l
1756 Q_PROCESSOR_ARM_V6, and \l Q_PROCESSOR_ARM_V7.
1757
1758 \sa QSysInfo::buildCpuArchitecture()
1759*/
1760/*!
1761 \macro Q_PROCESSOR_ARM_V5
1762 \relates <QtGlobal>
1763
1764 Defined if the application is compiled for ARMv5 processors. The \l
1765 Q_PROCESSOR_ARM macro is also defined when Q_PROCESSOR_ARM_V5 is defined.
1766
1767 \sa QSysInfo::buildCpuArchitecture()
1768*/
1769/*!
1770 \macro Q_PROCESSOR_ARM_V6
1771 \relates <QtGlobal>
1772
1773 Defined if the application is compiled for ARMv6 processors. The \l
1774 Q_PROCESSOR_ARM and \l Q_PROCESSOR_ARM_V5 macros are also defined when
1775 Q_PROCESSOR_ARM_V6 is defined.
1776
1777 \sa QSysInfo::buildCpuArchitecture()
1778*/
1779/*!
1780 \macro Q_PROCESSOR_ARM_V7
1781 \relates <QtGlobal>
1782
1783 Defined if the application is compiled for ARMv7 processors. The \l
1784 Q_PROCESSOR_ARM, \l Q_PROCESSOR_ARM_V5, and \l Q_PROCESSOR_ARM_V6 macros
1785 are also defined when Q_PROCESSOR_ARM_V7 is defined.
1786
1787 \sa QSysInfo::buildCpuArchitecture()
1788*/
1789
1790/*!
1791 \macro Q_PROCESSOR_AVR32
1792 \relates <QtGlobal>
1793
1794 Defined if the application is compiled for AVR32 processors.
1795
1796 \sa QSysInfo::buildCpuArchitecture()
1797*/
1798
1799/*!
1800 \macro Q_PROCESSOR_BLACKFIN
1801 \relates <QtGlobal>
1802
1803 Defined if the application is compiled for Blackfin processors.
1804
1805 \sa QSysInfo::buildCpuArchitecture()
1806*/
1807
1808/*!
1809 \macro Q_PROCESSOR_IA64
1810 \relates <QtGlobal>
1811
1812 Defined if the application is compiled for IA-64 processors. This includes
1813 all Itanium and Itanium 2 processors.
1814
1815 \sa QSysInfo::buildCpuArchitecture()
1816*/
1817
1818/*!
1819 \macro Q_PROCESSOR_MIPS
1820 \relates <QtGlobal>
1821
1822 Defined if the application is compiled for MIPS processors. Qt currently
1823 supports seven MIPS revisions: \l Q_PROCESSOR_MIPS_I, \l
1824 Q_PROCESSOR_MIPS_II, \l Q_PROCESSOR_MIPS_III, \l Q_PROCESSOR_MIPS_IV, \l
1825 Q_PROCESSOR_MIPS_V, \l Q_PROCESSOR_MIPS_32, and \l Q_PROCESSOR_MIPS_64.
1826
1827 \sa QSysInfo::buildCpuArchitecture()
1828*/
1829/*!
1830 \macro Q_PROCESSOR_MIPS_I
1831 \relates <QtGlobal>
1832
1833 Defined if the application is compiled for MIPS-I processors. The \l
1834 Q_PROCESSOR_MIPS macro is also defined when Q_PROCESSOR_MIPS_I is defined.
1835
1836 \sa QSysInfo::buildCpuArchitecture()
1837*/
1838/*!
1839 \macro Q_PROCESSOR_MIPS_II
1840 \relates <QtGlobal>
1841
1842 Defined if the application is compiled for MIPS-II processors. The \l
1843 Q_PROCESSOR_MIPS and \l Q_PROCESSOR_MIPS_I macros are also defined when
1844 Q_PROCESSOR_MIPS_II is defined.
1845
1846 \sa QSysInfo::buildCpuArchitecture()
1847*/
1848/*!
1849 \macro Q_PROCESSOR_MIPS_32
1850 \relates <QtGlobal>
1851
1852 Defined if the application is compiled for MIPS32 processors. The \l
1853 Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, and \l Q_PROCESSOR_MIPS_II macros
1854 are also defined when Q_PROCESSOR_MIPS_32 is defined.
1855
1856 \sa QSysInfo::buildCpuArchitecture()
1857*/
1858/*!
1859 \macro Q_PROCESSOR_MIPS_III
1860 \relates <QtGlobal>
1861
1862 Defined if the application is compiled for MIPS-III processors. The \l
1863 Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, and \l Q_PROCESSOR_MIPS_II macros
1864 are also defined when Q_PROCESSOR_MIPS_III is defined.
1865
1866 \sa QSysInfo::buildCpuArchitecture()
1867*/
1868/*!
1869 \macro Q_PROCESSOR_MIPS_IV
1870 \relates <QtGlobal>
1871
1872 Defined if the application is compiled for MIPS-IV processors. The \l
1873 Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, \l Q_PROCESSOR_MIPS_II, and \l
1874 Q_PROCESSOR_MIPS_III macros are also defined when Q_PROCESSOR_MIPS_IV is
1875 defined.
1876
1877 \sa QSysInfo::buildCpuArchitecture()
1878*/
1879/*!
1880 \macro Q_PROCESSOR_MIPS_V
1881 \relates <QtGlobal>
1882
1883 Defined if the application is compiled for MIPS-V processors. The \l
1884 Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, \l Q_PROCESSOR_MIPS_II, \l
1885 Q_PROCESSOR_MIPS_III, and \l Q_PROCESSOR_MIPS_IV macros are also defined
1886 when Q_PROCESSOR_MIPS_V is defined.
1887
1888 \sa QSysInfo::buildCpuArchitecture()
1889*/
1890/*!
1891 \macro Q_PROCESSOR_MIPS_64
1892 \relates <QtGlobal>
1893
1894 Defined if the application is compiled for MIPS64 processors. The \l
1895 Q_PROCESSOR_MIPS, \l Q_PROCESSOR_MIPS_I, \l Q_PROCESSOR_MIPS_II, \l
1896 Q_PROCESSOR_MIPS_III, \l Q_PROCESSOR_MIPS_IV, and \l Q_PROCESSOR_MIPS_V
1897 macros are also defined when Q_PROCESSOR_MIPS_64 is defined.
1898
1899 \sa QSysInfo::buildCpuArchitecture()
1900*/
1901
1902/*!
1903 \macro Q_PROCESSOR_POWER
1904 \relates <QtGlobal>
1905
1906 Defined if the application is compiled for POWER processors. Qt currently
1907 supports two Power variants: \l Q_PROCESSOR_POWER_32 and \l
1908 Q_PROCESSOR_POWER_64.
1909
1910 \sa QSysInfo::buildCpuArchitecture()
1911*/
1912/*!
1913 \macro Q_PROCESSOR_POWER_32
1914 \relates <QtGlobal>
1915
1916 Defined if the application is compiled for 32-bit Power processors. The \l
1917 Q_PROCESSOR_POWER macro is also defined when Q_PROCESSOR_POWER_32 is
1918 defined.
1919
1920 \sa QSysInfo::buildCpuArchitecture()
1921*/
1922/*!
1923 \macro Q_PROCESSOR_POWER_64
1924 \relates <QtGlobal>
1925
1926 Defined if the application is compiled for 64-bit Power processors. The \l
1927 Q_PROCESSOR_POWER macro is also defined when Q_PROCESSOR_POWER_64 is
1928 defined.
1929
1930 \sa QSysInfo::buildCpuArchitecture()
1931*/
1932
1933/*!
1934 \macro Q_PROCESSOR_RISCV
1935 \relates <QtGlobal>
1936 \since 5.13
1937
1938 Defined if the application is compiled for RISC-V processors. Qt currently
1939 supports two RISC-V variants: \l Q_PROCESSOR_RISCV_32 and \l
1940 Q_PROCESSOR_RISCV_64.
1941
1942 \sa QSysInfo::buildCpuArchitecture()
1943*/
1944
1945/*!
1946 \macro Q_PROCESSOR_RISCV_32
1947 \relates <QtGlobal>
1948 \since 5.13
1949
1950 Defined if the application is compiled for 32-bit RISC-V processors. The \l
1951 Q_PROCESSOR_RISCV macro is also defined when Q_PROCESSOR_RISCV_32 is
1952 defined.
1953
1954 \sa QSysInfo::buildCpuArchitecture()
1955*/
1956
1957/*!
1958 \macro Q_PROCESSOR_RISCV_64
1959 \relates <QtGlobal>
1960 \since 5.13
1961
1962 Defined if the application is compiled for 64-bit RISC-V processors. The \l
1963 Q_PROCESSOR_RISCV macro is also defined when Q_PROCESSOR_RISCV_64 is
1964 defined.
1965
1966 \sa QSysInfo::buildCpuArchitecture()
1967*/
1968
1969/*!
1970 \macro Q_PROCESSOR_S390
1971 \relates <QtGlobal>
1972
1973 Defined if the application is compiled for S/390 processors. Qt supports
1974 one optional variant of S/390: Q_PROCESSOR_S390_X.
1975
1976 \sa QSysInfo::buildCpuArchitecture()
1977*/
1978/*!
1979 \macro Q_PROCESSOR_S390_X
1980 \relates <QtGlobal>
1981
1982 Defined if the application is compiled for S/390x processors. The \l
1983 Q_PROCESSOR_S390 macro is also defined when Q_PROCESSOR_S390_X is defined.
1984
1985 \sa QSysInfo::buildCpuArchitecture()
1986*/
1987
1988/*!
1989 \macro Q_PROCESSOR_SH
1990 \relates <QtGlobal>
1991
1992 Defined if the application is compiled for SuperH processors. Qt currently
1993 supports one SuperH revision: \l Q_PROCESSOR_SH_4A.
1994
1995 \sa QSysInfo::buildCpuArchitecture()
1996*/
1997/*!
1998 \macro Q_PROCESSOR_SH_4A
1999 \relates <QtGlobal>
2000
2001 Defined if the application is compiled for SuperH 4A processors. The \l
2002 Q_PROCESSOR_SH macro is also defined when Q_PROCESSOR_SH_4A is defined.
2003
2004 \sa QSysInfo::buildCpuArchitecture()
2005*/
2006
2007/*!
2008 \macro Q_PROCESSOR_SPARC
2009 \relates <QtGlobal>
2010
2011 Defined if the application is compiled for SPARC processors. Qt currently
2012 supports one optional SPARC revision: \l Q_PROCESSOR_SPARC_V9.
2013
2014 \sa QSysInfo::buildCpuArchitecture()
2015*/
2016/*!
2017 \macro Q_PROCESSOR_SPARC_V9
2018 \relates <QtGlobal>
2019
2020 Defined if the application is compiled for SPARC V9 processors. The \l
2021 Q_PROCESSOR_SPARC macro is also defined when Q_PROCESSOR_SPARC_V9 is
2022 defined.
2023
2024 \sa QSysInfo::buildCpuArchitecture()
2025*/
2026
2027/*!
2028 \macro Q_PROCESSOR_X86
2029 \relates <QtGlobal>
2030
2031 Defined if the application is compiled for x86 processors. Qt currently
2032 supports two x86 variants: \l Q_PROCESSOR_X86_32 and \l Q_PROCESSOR_X86_64.
2033
2034 \sa QSysInfo::buildCpuArchitecture()
2035*/
2036/*!
2037 \macro Q_PROCESSOR_X86_32
2038 \relates <QtGlobal>
2039
2040 Defined if the application is compiled for 32-bit x86 processors. This
2041 includes all i386, i486, i586, and i686 processors. The \l Q_PROCESSOR_X86
2042 macro is also defined when Q_PROCESSOR_X86_32 is defined.
2043
2044 \sa QSysInfo::buildCpuArchitecture()
2045*/
2046/*!
2047 \macro Q_PROCESSOR_X86_64
2048 \relates <QtGlobal>
2049
2050 Defined if the application is compiled for 64-bit x86 processors. This
2051 includes all AMD64, Intel 64, and other x86_64/x64 processors. The \l
2052 Q_PROCESSOR_X86 macro is also defined when Q_PROCESSOR_X86_64 is defined.
2053
2054 \sa QSysInfo::buildCpuArchitecture()
2055*/
2056
2057/*!
2058 \macro QT_DISABLE_DEPRECATED_BEFORE
2059 \relates <QtGlobal>
2060
2061 This macro can be defined in the project file to disable functions deprecated in
2062 a specified version of Qt or any earlier version. The default version number is 5.0,
2063 meaning that functions deprecated in or before Qt 5.0 will not be included.
2064
2065 For instance, when using a future release of Qt 5, set
2066 \c{QT_DISABLE_DEPRECATED_BEFORE=0x050100} to disable functions deprecated in
2067 Qt 5.1 and earlier. In any release, set
2068 \c{QT_DISABLE_DEPRECATED_BEFORE=0x000000} to enable all functions, including
2069 the ones deprecated in Qt 5.0.
2070
2071 \sa QT_DEPRECATED_WARNINGS
2072 */
2073
2074
2075/*!
2076 \macro QT_DEPRECATED_WARNINGS
2077 \relates <QtGlobal>
2078
2079 Since Qt 5.13, this macro has no effect. In Qt 5.12 and before, if this macro
2080 is defined, the compiler will generate warnings if any API declared as
2081 deprecated by Qt is used.
2082
2083 \sa QT_DISABLE_DEPRECATED_BEFORE, QT_NO_DEPRECATED_WARNINGS
2084 */
2085
2086/*!
2087 \macro QT_NO_DEPRECATED_WARNINGS
2088 \relates <QtGlobal>
2089 \since 5.13
2090
2091 This macro can be used to suppress deprecation warnings that would otherwise
2092 be generated when using deprecated APIs.
2093
2094 \sa QT_DISABLE_DEPRECATED_BEFORE
2095*/
2096
2097#if defined(QT_BUILD_QMAKE)
2098// needed to bootstrap qmake
2099static const unsigned int qt_one = 1;
2100const int QSysInfo::ByteOrder = ((*((unsigned char *) &qt_one) == 0) ? BigEndian : LittleEndian);
2101#endif
2102
2103#if defined(Q_OS_MAC)
2104
2105QT_BEGIN_INCLUDE_NAMESPACE
2106#include "private/qcore_mac_p.h"
2107#include "qnamespace.h"
2108QT_END_INCLUDE_NAMESPACE
2109
2110#if QT_DEPRECATED_SINCE(5, 9)
2111QT_WARNING_PUSH
2112QT_WARNING_DISABLE_DEPRECATED
2113QSysInfo::MacVersion QSysInfo::macVersion()
2114{
2115 const auto version = QOperatingSystemVersion::current();
2116#if defined(Q_OS_MACOS)
2117 return QSysInfo::MacVersion(Q_MV_OSX(version.majorVersion(), version.minorVersion()));
2118#elif defined(Q_OS_IOS)
2119 return QSysInfo::MacVersion(Q_MV_IOS(version.majorVersion(), version.minorVersion()));
2120#elif defined(Q_OS_TVOS)
2121 return QSysInfo::MacVersion(Q_MV_TVOS(version.majorVersion(), version.minorVersion()));
2122#elif defined(Q_OS_WATCHOS)
2123 return QSysInfo::MacVersion(Q_MV_WATCHOS(version.majorVersion(), version.minorVersion()));
2124#else
2125 return QSysInfo::MV_Unknown;
2126#endif
2127}
2128const QSysInfo::MacVersion QSysInfo::MacintoshVersion = QSysInfo::macVersion();
2129QT_WARNING_POP
2130#endif
2131
2132#ifdef Q_OS_DARWIN
2133static const char *osVer_helper(QOperatingSystemVersion version = QOperatingSystemVersion::current())
2134{
2135#ifdef Q_OS_MACOS
2136 if (version.majorVersion() == 10) {
2137 switch (version.minorVersion()) {
2138 case 9:
2139 return "Mavericks";
2140 case 10:
2141 return "Yosemite";
2142 case 11:
2143 return "El Capitan";
2144 case 12:
2145 return "Sierra";
2146 case 13:
2147 return "High Sierra";
2148 case 14:
2149 return "Mojave";
2150 }
2151 }
2152 // unknown, future version
2153#else
2154 Q_UNUSED(version);
2155#endif
2156 return 0;
2157}
2158#endif
2159
2160#elif defined(Q_OS_WIN) || defined(Q_OS_CYGWIN) || defined(Q_OS_WINRT)
2161
2162QT_BEGIN_INCLUDE_NAMESPACE
2163#include "qt_windows.h"
2164QT_END_INCLUDE_NAMESPACE
2165
2166# ifndef QT_BOOTSTRAPPED
2167class QWindowsSockInit
2168{
2169public:
2170 QWindowsSockInit();
2171 ~QWindowsSockInit();
2172 int version;
2173};
2174
2175QWindowsSockInit::QWindowsSockInit()
2176: version(0)
2177{
2178 //### should we try for 2.2 on all platforms ??
2179 WSAData wsadata;
2180
2181 // IPv6 requires Winsock v2.0 or better.
2182 if (WSAStartup(MAKEWORD(2,0), &wsadata) != 0) {
2183 qWarning("QTcpSocketAPI: WinSock v2.0 initialization failed.");
2184 } else {
2185 version = 0x20;
2186 }
2187}
2188
2189QWindowsSockInit::~QWindowsSockInit()
2190{
2191 WSACleanup();
2192}
2193Q_GLOBAL_STATIC(QWindowsSockInit, winsockInit)
2194# endif // QT_BOOTSTRAPPED
2195
2196#if QT_DEPRECATED_SINCE(5, 9)
2197QT_WARNING_PUSH
2198QT_WARNING_DISABLE_DEPRECATED
2199QSysInfo::WinVersion QSysInfo::windowsVersion()
2200{
2201 const auto version = QOperatingSystemVersion::current();
2202 if (version.majorVersion() == 6 && version.minorVersion() == 1)
2203 return QSysInfo::WV_WINDOWS7;
2204 if (version.majorVersion() == 6 && version.minorVersion() == 2)
2205 return QSysInfo::WV_WINDOWS8;
2206 if (version.majorVersion() == 6 && version.minorVersion() == 3)
2207 return QSysInfo::WV_WINDOWS8_1;
2208 if (version.majorVersion() == 10 && version.minorVersion() == 0)
2209 return QSysInfo::WV_WINDOWS10;
2210 return QSysInfo::WV_NT_based;
2211}
2212const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion();
2213QT_WARNING_POP
2214#endif
2215
2216static QString readVersionRegistryString(const wchar_t *subKey)
2217{
2218#if !defined(QT_BUILD_QMAKE) && !defined(Q_OS_WINRT)
2219 return QWinRegistryKey(HKEY_LOCAL_MACHINE, LR"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)")
2220 .stringValue(subKey);
2221#else
2222 Q_UNUSED(subKey);
2223 return QString();
2224#endif
2225}
2226
2227static inline QString windows10ReleaseId()
2228{
2229 return readVersionRegistryString(L"ReleaseId");
2230}
2231
2232static inline QString windows7Build()
2233{
2234 return readVersionRegistryString(L"CurrentBuild");
2235}
2236
2237static QString winSp_helper()
2238{
2239 const auto osv = qWindowsVersionInfo();
2240 const qint16 major = osv.wServicePackMajor;
2241 if (major) {
2242 QString sp = QStringLiteral("SP ") + QString::number(major);
2243 const qint16 minor = osv.wServicePackMinor;
2244 if (minor)
2245 sp += QLatin1Char('.') + QString::number(minor);
2246
2247 return sp;
2248 }
2249 return QString();
2250}
2251
2252static const char *osVer_helper(QOperatingSystemVersion version = QOperatingSystemVersion::current())
2253{
2254 Q_UNUSED(version);
2255 const OSVERSIONINFOEX osver = qWindowsVersionInfo();
2256 const bool workstation = osver.wProductType == VER_NT_WORKSTATION;
2257
2258#define Q_WINVER(major, minor) (major << 8 | minor)
2259 switch (Q_WINVER(osver.dwMajorVersion, osver.dwMinorVersion)) {
2260 case Q_WINVER(6, 1):
2261 return workstation ? "7" : "Server 2008 R2";
2262 case Q_WINVER(6, 2):
2263 return workstation ? "8" : "Server 2012";
2264 case Q_WINVER(6, 3):
2265 return workstation ? "8.1" : "Server 2012 R2";
2266 case Q_WINVER(10, 0):
2267 if (workstation) {
2268 if (osver.dwBuildNumber >= 22000)
2269 return "11";
2270 return "10";
2271 }
2272 // else: Server
2273 if (osver.dwBuildNumber >= 20348)
2274 return "Server 2022";
2275 if (osver.dwBuildNumber >= 17763)
2276 return "Server 2019";
2277 return "Server 2016";
2278 }
2279#undef Q_WINVER
2280 // unknown, future version
2281 return 0;
2282}
2283
2284#endif
2285#if defined(Q_OS_UNIX)
2286# if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) || defined(Q_OS_FREEBSD)
2287# define USE_ETC_OS_RELEASE
2288struct QUnixOSVersion
2289{
2290 // from /etc/os-release older /etc/lsb-release // redhat /etc/redhat-release // debian /etc/debian_version
2291 QString productType; // $ID $DISTRIB_ID // single line file containing: // Debian
2292 QString productVersion; // $VERSION_ID $DISTRIB_RELEASE // <Vendor_ID release Version_ID> // single line file <Release_ID/sid>
2293 QString prettyName; // $PRETTY_NAME $DISTRIB_DESCRIPTION
2294};
2295
2296static QString unquote(const char *begin, const char *end)
2297{
2298 // man os-release says:
2299 // Variable assignment values must be enclosed in double
2300 // or single quotes if they include spaces, semicolons or
2301 // other special characters outside of A–Z, a–z, 0–9. Shell
2302 // special characters ("$", quotes, backslash, backtick)
2303 // must be escaped with backslashes, following shell style.
2304 // All strings should be in UTF-8 format, and non-printable
2305 // characters should not be used. It is not supported to
2306 // concatenate multiple individually quoted strings.
2307 if (*begin == '"') {
2308 Q_ASSERT(end[-1] == '"');
2309 return QString::fromUtf8(str: begin + 1, size: end - begin - 2);
2310 }
2311 return QString::fromUtf8(str: begin, size: end - begin);
2312}
2313static QByteArray getEtcFileContent(const char *filename)
2314{
2315 // we're avoiding QFile here
2316 int fd = qt_safe_open(pathname: filename, O_RDONLY);
2317 if (fd == -1)
2318 return QByteArray();
2319
2320 QT_STATBUF sbuf;
2321 if (QT_FSTAT(fd: fd, buf: &sbuf) == -1) {
2322 qt_safe_close(fd);
2323 return QByteArray();
2324 }
2325
2326 QByteArray buffer(sbuf.st_size, Qt::Uninitialized);
2327 buffer.resize(size: qt_safe_read(fd, data: buffer.data(), maxlen: sbuf.st_size));
2328 qt_safe_close(fd);
2329 return buffer;
2330}
2331
2332static bool readEtcFile(QUnixOSVersion &v, const char *filename,
2333 const QByteArray &idKey, const QByteArray &versionKey, const QByteArray &prettyNameKey)
2334{
2335
2336 QByteArray buffer = getEtcFileContent(filename);
2337 if (buffer.isEmpty())
2338 return false;
2339
2340 const char *ptr = buffer.constData();
2341 const char *end = buffer.constEnd();
2342 const char *eol;
2343 QByteArray line;
2344 for ( ; ptr != end; ptr = eol + 1) {
2345 // find the end of the line after ptr
2346 eol = static_cast<const char *>(memchr(s: ptr, c: '\n', n: end - ptr));
2347 if (!eol)
2348 eol = end - 1;
2349 line.setRawData(a: ptr, n: eol - ptr);
2350
2351 if (line.startsWith(a: idKey)) {
2352 ptr += idKey.length();
2353 v.productType = unquote(begin: ptr, end: eol);
2354 continue;
2355 }
2356
2357 if (line.startsWith(a: prettyNameKey)) {
2358 ptr += prettyNameKey.length();
2359 v.prettyName = unquote(begin: ptr, end: eol);
2360 continue;
2361 }
2362
2363 if (line.startsWith(a: versionKey)) {
2364 ptr += versionKey.length();
2365 v.productVersion = unquote(begin: ptr, end: eol);
2366 continue;
2367 }
2368 }
2369
2370 return true;
2371}
2372
2373static bool readOsRelease(QUnixOSVersion &v)
2374{
2375 QByteArray id = QByteArrayLiteral("ID=");
2376 QByteArray versionId = QByteArrayLiteral("VERSION_ID=");
2377 QByteArray prettyName = QByteArrayLiteral("PRETTY_NAME=");
2378
2379 // man os-release(5) says:
2380 // The file /etc/os-release takes precedence over /usr/lib/os-release.
2381 // Applications should check for the former, and exclusively use its data
2382 // if it exists, and only fall back to /usr/lib/os-release if it is
2383 // missing.
2384 return readEtcFile(v, filename: "/etc/os-release", idKey: id, versionKey: versionId, prettyNameKey: prettyName) ||
2385 readEtcFile(v, filename: "/usr/lib/os-release", idKey: id, versionKey: versionId, prettyNameKey: prettyName);
2386}
2387
2388static bool readEtcLsbRelease(QUnixOSVersion &v)
2389{
2390 bool ok = readEtcFile(v, filename: "/etc/lsb-release", QByteArrayLiteral("DISTRIB_ID="),
2391 QByteArrayLiteral("DISTRIB_RELEASE="), QByteArrayLiteral("DISTRIB_DESCRIPTION="));
2392 if (ok && (v.prettyName.isEmpty() || v.prettyName == v.productType)) {
2393 // some distributions have redundant information for the pretty name,
2394 // so try /etc/<lowercasename>-release
2395
2396 // we're still avoiding QFile here
2397 QByteArray distrorelease = "/etc/" + v.productType.toLatin1().toLower() + "-release";
2398 int fd = qt_safe_open(pathname: distrorelease, O_RDONLY);
2399 if (fd != -1) {
2400 QT_STATBUF sbuf;
2401 if (QT_FSTAT(fd: fd, buf: &sbuf) != -1 && sbuf.st_size > v.prettyName.length()) {
2402 // file apparently contains interesting information
2403 QByteArray buffer(sbuf.st_size, Qt::Uninitialized);
2404 buffer.resize(size: qt_safe_read(fd, data: buffer.data(), maxlen: sbuf.st_size));
2405 v.prettyName = QString::fromLatin1(str: buffer.trimmed());
2406 }
2407 qt_safe_close(fd);
2408 }
2409 }
2410
2411 // some distributions have a /etc/lsb-release file that does not provide the values
2412 // we are looking for, i.e. DISTRIB_ID, DISTRIB_RELEASE and DISTRIB_DESCRIPTION.
2413 // Assuming that neither DISTRIB_ID nor DISTRIB_RELEASE were found, or contained valid values,
2414 // returning false for readEtcLsbRelease will allow further /etc/<lowercasename>-release parsing.
2415 return ok && !(v.productType.isEmpty() && v.productVersion.isEmpty());
2416}
2417
2418#if defined(Q_OS_LINUX)
2419static QByteArray getEtcFileFirstLine(const char *fileName)
2420{
2421 QByteArray buffer = getEtcFileContent(filename: fileName);
2422 if (buffer.isEmpty())
2423 return QByteArray();
2424
2425 const char *ptr = buffer.constData();
2426 int eol = buffer.indexOf(c: "\n");
2427 return QByteArray(ptr, eol).trimmed();
2428}
2429
2430static bool readEtcRedHatRelease(QUnixOSVersion &v)
2431{
2432 // /etc/redhat-release analysed should be a one line file
2433 // the format of its content is <Vendor_ID release Version>
2434 // i.e. "Red Hat Enterprise Linux Workstation release 6.5 (Santiago)"
2435 QByteArray line = getEtcFileFirstLine(fileName: "/etc/redhat-release");
2436 if (line.isEmpty())
2437 return false;
2438
2439 v.prettyName = QString::fromLatin1(str: line);
2440
2441 const char keyword[] = "release ";
2442 int releaseIndex = line.indexOf(c: keyword);
2443 v.productType = QString::fromLatin1(str: line.mid(index: 0, len: releaseIndex)).remove(c: QLatin1Char(' '));
2444 int spaceIndex = line.indexOf(c: ' ', from: releaseIndex + strlen(s: keyword));
2445 v.productVersion = QString::fromLatin1(str: line.mid(index: releaseIndex + strlen(s: keyword),
2446 len: spaceIndex > -1 ? spaceIndex - releaseIndex - int(strlen(s: keyword)) : -1));
2447 return true;
2448}
2449
2450static bool readEtcDebianVersion(QUnixOSVersion &v)
2451{
2452 // /etc/debian_version analysed should be a one line file
2453 // the format of its content is <Release_ID/sid>
2454 // i.e. "jessie/sid"
2455 QByteArray line = getEtcFileFirstLine(fileName: "/etc/debian_version");
2456 if (line.isEmpty())
2457 return false;
2458
2459 v.productType = QStringLiteral("Debian");
2460 v.productVersion = QString::fromLatin1(str: line);
2461 return true;
2462}
2463#endif
2464
2465static bool findUnixOsVersion(QUnixOSVersion &v)
2466{
2467 if (readOsRelease(v))
2468 return true;
2469 if (readEtcLsbRelease(v))
2470 return true;
2471#if defined(Q_OS_LINUX)
2472 if (readEtcRedHatRelease(v))
2473 return true;
2474 if (readEtcDebianVersion(v))
2475 return true;
2476#endif
2477 return false;
2478}
2479# endif // USE_ETC_OS_RELEASE
2480#endif // Q_OS_UNIX
2481
2482#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
2483static const char *osVer_helper(QOperatingSystemVersion)
2484{
2485/* Data:
2486
2487
2488
2489Cupcake
2490Donut
2491Eclair
2492Eclair
2493Eclair
2494Froyo
2495Gingerbread
2496Gingerbread
2497Honeycomb
2498Honeycomb
2499Honeycomb
2500Ice Cream Sandwich
2501Ice Cream Sandwich
2502Jelly Bean
2503Jelly Bean
2504Jelly Bean
2505KitKat
2506KitKat
2507Lollipop
2508Lollipop
2509Marshmallow
2510Nougat
2511Nougat
2512Oreo
2513 */
2514 static const char versions_string[] =
2515 "\0"
2516 "Cupcake\0"
2517 "Donut\0"
2518 "Eclair\0"
2519 "Froyo\0"
2520 "Gingerbread\0"
2521 "Honeycomb\0"
2522 "Ice Cream Sandwich\0"
2523 "Jelly Bean\0"
2524 "KitKat\0"
2525 "Lollipop\0"
2526 "Marshmallow\0"
2527 "Nougat\0"
2528 "Oreo\0"
2529 "\0";
2530
2531 static const int versions_indices[] = {
2532 0, 0, 0, 1, 9, 15, 15, 15,
2533 22, 28, 28, 40, 40, 40, 50, 50,
2534 69, 69, 69, 80, 80, 87, 87, 96,
2535 108, 108, 115, -1
2536 };
2537
2538 static const int versions_count = (sizeof versions_indices) / (sizeof versions_indices[0]);
2539
2540 // https://source.android.com/source/build-numbers.html
2541 // https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels
2542 const int sdk_int = QJNIObjectPrivate::getStaticField<jint>("android/os/Build$VERSION", "SDK_INT");
2543 return &versions_string[versions_indices[qBound(0, sdk_int, versions_count - 1)]];
2544}
2545#endif
2546
2547/*!
2548 \since 5.4
2549
2550 Returns the architecture of the CPU that Qt was compiled for, in text
2551 format. Note that this may not match the actual CPU that the application is
2552 running on if there's an emulation layer or if the CPU supports multiple
2553 architectures (like x86-64 processors supporting i386 applications). To
2554 detect that, use currentCpuArchitecture().
2555
2556 Values returned by this function are stable and will not change over time,
2557 so applications can rely on the returned value as an identifier, except
2558 that new CPU types may be added over time.
2559
2560 Typical returned values are (note: list not exhaustive):
2561 \list
2562 \li "arm"
2563 \li "arm64"
2564 \li "i386"
2565 \li "ia64"
2566 \li "mips"
2567 \li "mips64"
2568 \li "power"
2569 \li "power64"
2570 \li "sparc"
2571 \li "sparcv9"
2572 \li "x86_64"
2573 \endlist
2574
2575 \sa QSysInfo::buildAbi(), QSysInfo::currentCpuArchitecture()
2576*/
2577QString QSysInfo::buildCpuArchitecture()
2578{
2579 return QStringLiteral(ARCH_PROCESSOR);
2580}
2581
2582/*!
2583 \since 5.4
2584
2585 Returns the architecture of the CPU that the application is running on, in
2586 text format. Note that this function depends on what the OS will report and
2587 may not detect the actual CPU architecture if the OS hides that information
2588 or is unable to provide it. For example, a 32-bit OS running on a 64-bit
2589 CPU is usually unable to determine the CPU is actually capable of running
2590 64-bit programs.
2591
2592 Values returned by this function are mostly stable: an attempt will be made
2593 to ensure that they stay constant over time and match the values returned
2594 by QSysInfo::builldCpuArchitecture(). However, due to the nature of the
2595 operating system functions being used, there may be discrepancies.
2596
2597 Typical returned values are (note: list not exhaustive):
2598 \list
2599 \li "arm"
2600 \li "arm64"
2601 \li "i386"
2602 \li "ia64"
2603 \li "mips"
2604 \li "mips64"
2605 \li "power"
2606 \li "power64"
2607 \li "sparc"
2608 \li "sparcv9"
2609 \li "x86_64"
2610 \endlist
2611
2612 \sa QSysInfo::buildAbi(), QSysInfo::buildCpuArchitecture()
2613 */
2614QString QSysInfo::currentCpuArchitecture()
2615{
2616#if defined(Q_OS_WIN)
2617 // We don't need to catch all the CPU architectures in this function;
2618 // only those where the host CPU might be different than the build target
2619 // (usually, 64-bit platforms).
2620 SYSTEM_INFO info;
2621 GetNativeSystemInfo(&info);
2622 switch (info.wProcessorArchitecture) {
2623# ifdef PROCESSOR_ARCHITECTURE_AMD64
2624 case PROCESSOR_ARCHITECTURE_AMD64:
2625 return QStringLiteral("x86_64");
2626# endif
2627# ifdef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
2628 case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
2629# endif
2630 case PROCESSOR_ARCHITECTURE_IA64:
2631 return QStringLiteral("ia64");
2632 }
2633#elif defined(Q_OS_DARWIN) && !defined(Q_OS_MACOS)
2634 // iOS-based OSes do not return the architecture on uname(2)'s result.
2635 return buildCpuArchitecture();
2636#elif defined(Q_OS_UNIX)
2637 long ret = -1;
2638 struct utsname u;
2639
2640# if defined(Q_OS_SOLARIS)
2641 // We need a special call for Solaris because uname(2) on x86 returns "i86pc" for
2642 // both 32- and 64-bit CPUs. Reference:
2643 // http://docs.oracle.com/cd/E18752_01/html/816-5167/sysinfo-2.html#REFMAN2sysinfo-2
2644 // http://fxr.watson.org/fxr/source/common/syscall/systeminfo.c?v=OPENSOLARIS
2645 // http://fxr.watson.org/fxr/source/common/conf/param.c?v=OPENSOLARIS;im=10#L530
2646 if (ret == -1)
2647 ret = sysinfo(SI_ARCHITECTURE_64, u.machine, sizeof u.machine);
2648# endif
2649
2650 if (ret == -1)
2651 ret = uname(name: &u);
2652
2653 // we could use detectUnixVersion() above, but we only need a field no other function does
2654 if (ret != -1) {
2655 // the use of QT_BUILD_INTERNAL here is simply to ensure all branches build
2656 // as we don't often build on some of the less common platforms
2657# if defined(Q_PROCESSOR_ARM) || defined(QT_BUILD_INTERNAL)
2658 if (strcmp(s1: u.machine, s2: "aarch64") == 0)
2659 return QStringLiteral("arm64");
2660 if (strncmp(s1: u.machine, s2: "armv", n: 4) == 0)
2661 return QStringLiteral("arm");
2662# endif
2663# if defined(Q_PROCESSOR_POWER) || defined(QT_BUILD_INTERNAL)
2664 // harmonize "powerpc" and "ppc" to "power"
2665 if (strncmp(s1: u.machine, s2: "ppc", n: 3) == 0)
2666 return QLatin1String("power") + QLatin1String(u.machine + 3);
2667 if (strncmp(s1: u.machine, s2: "powerpc", n: 7) == 0)
2668 return QLatin1String("power") + QLatin1String(u.machine + 7);
2669 if (strcmp(s1: u.machine, s2: "Power Macintosh") == 0)
2670 return QLatin1String("power");
2671# endif
2672# if defined(Q_PROCESSOR_SPARC) || defined(QT_BUILD_INTERNAL)
2673 // Solaris sysinfo(2) (above) uses "sparcv9", but uname -m says "sun4u";
2674 // Linux says "sparc64"
2675 if (strcmp(s1: u.machine, s2: "sun4u") == 0 || strcmp(s1: u.machine, s2: "sparc64") == 0)
2676 return QStringLiteral("sparcv9");
2677 if (strcmp(s1: u.machine, s2: "sparc32") == 0)
2678 return QStringLiteral("sparc");
2679# endif
2680# if defined(Q_PROCESSOR_X86) || defined(QT_BUILD_INTERNAL)
2681 // harmonize all "i?86" to "i386"
2682 if (strlen(s: u.machine) == 4 && u.machine[0] == 'i'
2683 && u.machine[2] == '8' && u.machine[3] == '6')
2684 return QStringLiteral("i386");
2685 if (strcmp(s1: u.machine, s2: "amd64") == 0) // Solaris
2686 return QStringLiteral("x86_64");
2687# endif
2688 return QString::fromLatin1(str: u.machine);
2689 }
2690#endif
2691 return buildCpuArchitecture();
2692}
2693
2694/*!
2695 \since 5.4
2696
2697 Returns the full architecture string that Qt was compiled for. This string
2698 is useful for identifying different, incompatible builds. For example, it
2699 can be used as an identifier to request an upgrade package from a server.
2700
2701 The values returned from this function are kept stable as follows: the
2702 mandatory components of the result will not change in future versions of
2703 Qt, but optional suffixes may be added.
2704
2705 The returned value is composed of three or more parts, separated by dashes
2706 ("-"). They are:
2707
2708 \table
2709 \header \li Component \li Value
2710 \row \li CPU Architecture \li The same as QSysInfo::buildCpuArchitecture(), such as "arm", "i386", "mips" or "x86_64"
2711 \row \li Endianness \li "little_endian" or "big_endian"
2712 \row \li Word size \li Whether it's a 32- or 64-bit application. Possible values are:
2713 "llp64" (Windows 64-bit), "lp64" (Unix 64-bit), "ilp32" (32-bit)
2714 \row \li (Optional) ABI \li Zero or more components identifying different ABIs possible in this architecture.
2715 Currently, Qt has optional ABI components for ARM and MIPS processors: one
2716 component is the main ABI (such as "eabi", "o32", "n32", "o64"); another is
2717 whether the calling convention is using hardware floating point registers ("hardfloat"
2718 is present).
2719
2720 Additionally, if Qt was configured with \c{-qreal float}, the ABI option tag "qreal_float"
2721 will be present. If Qt was configured with another type as qreal, that type is present after
2722 "qreal_", with all characters other than letters and digits escaped by an underscore, followed
2723 by two hex digits. For example, \c{-qreal long double} becomes "qreal_long_20double".
2724 \endtable
2725
2726 \sa QSysInfo::buildCpuArchitecture()
2727*/
2728QString QSysInfo::buildAbi()
2729{
2730#ifdef Q_COMPILER_UNICODE_STRINGS
2731 // ARCH_FULL is a concatenation of strings (incl. ARCH_PROCESSOR), which breaks
2732 // QStringLiteral on MSVC. Since the concatenation behavior we want is specified
2733 // the same C++11 paper as the Unicode strings, we'll use that macro and hope
2734 // that Microsoft implements the new behavior when they add support for Unicode strings.
2735 return QStringLiteral(ARCH_FULL);
2736#else
2737 return QLatin1String(ARCH_FULL);
2738#endif
2739}
2740
2741static QString unknownText()
2742{
2743 return QStringLiteral("unknown");
2744}
2745
2746/*!
2747 \since 5.4
2748
2749 Returns the type of the operating system kernel Qt was compiled for. It's
2750 also the kernel the application is running on, unless the host operating
2751 system is running a form of compatibility or virtualization layer.
2752
2753 Values returned by this function are stable and will not change over time,
2754 so applications can rely on the returned value as an identifier, except
2755 that new OS kernel types may be added over time.
2756
2757 On Windows, this function returns the type of Windows kernel, like "winnt".
2758 On Unix systems, it returns the same as the output of \c{uname
2759 -s} (lowercased).
2760
2761 \note This function may return surprising values: it returns "linux"
2762 for all operating systems running Linux (including Android), "qnx" for all
2763 operating systems running QNX, "freebsd" for
2764 Debian/kFreeBSD, and "darwin" for \macos and iOS. For information on the type
2765 of product the application is running on, see productType().
2766
2767 \sa QFileSelector, kernelVersion(), productType(), productVersion(), prettyProductName()
2768*/
2769QString QSysInfo::kernelType()
2770{
2771#if defined(Q_OS_WIN)
2772 return QStringLiteral("winnt");
2773#elif defined(Q_OS_UNIX)
2774 struct utsname u;
2775 if (uname(name: &u) == 0)
2776 return QString::fromLatin1(str: u.sysname).toLower();
2777#endif
2778 return unknownText();
2779}
2780
2781/*!
2782 \since 5.4
2783
2784 Returns the release version of the operating system kernel. On Windows, it
2785 returns the version of the NT kernel. On Unix systems, including
2786 Android and \macos, it returns the same as the \c{uname -r}
2787 command would return.
2788
2789 If the version could not be determined, this function may return an empty
2790 string.
2791
2792 \sa kernelType(), productType(), productVersion(), prettyProductName()
2793*/
2794QString QSysInfo::kernelVersion()
2795{
2796#ifdef Q_OS_WIN
2797 const auto osver = QOperatingSystemVersion::current();
2798 return QString::number(osver.majorVersion()) + QLatin1Char('.') + QString::number(osver.minorVersion())
2799 + QLatin1Char('.') + QString::number(osver.microVersion());
2800#else
2801 struct utsname u;
2802 if (uname(name: &u) == 0)
2803 return QString::fromLatin1(str: u.release);
2804 return QString();
2805#endif
2806}
2807
2808
2809/*!
2810 \since 5.4
2811
2812 Returns the product name of the operating system this application is
2813 running in. If the application is running on some sort of emulation or
2814 virtualization layer (such as WINE on a Unix system), this function will
2815 inspect the emulation / virtualization layer.
2816
2817 Values returned by this function are stable and will not change over time,
2818 so applications can rely on the returned value as an identifier, except
2819 that new OS types may be added over time.
2820
2821 \b{Linux and Android note}: this function returns "android" for Linux
2822 systems running Android userspace, notably when using the Bionic library.
2823 For all other Linux systems, regardless of C library being used, it tries
2824 to determine the distribution name and returns that. If determining the
2825 distribution name failed, it returns "unknown".
2826
2827 \b{\macos note}: this function returns "osx" for all \macos systems,
2828 regardless of Apple naming convention. The returned string will be updated
2829 for Qt 6. Note that this function erroneously returned "macos" for \macos
2830 10.12 in Qt versions 5.6.2, 5.7.1, and 5.8.0.
2831
2832 \b{Darwin, iOS, tvOS, and watchOS note}: this function returns "ios" for
2833 iOS systems, "tvos" for tvOS systems, "watchos" for watchOS systems, and
2834 "darwin" in case the system could not be determined.
2835
2836 \b{FreeBSD note}: this function returns "debian" for Debian/kFreeBSD and
2837 "unknown" otherwise.
2838
2839 \b{Windows note}: this function "winrt" for WinRT builds, and "windows"
2840 for normal desktop builds.
2841
2842 For other Unix-type systems, this function usually returns "unknown".
2843
2844 \sa QFileSelector, kernelType(), kernelVersion(), productVersion(), prettyProductName()
2845*/
2846QString QSysInfo::productType()
2847{
2848 // similar, but not identical to QFileSelectorPrivate::platformSelectors
2849#if defined(Q_OS_WINRT)
2850 return QStringLiteral("winrt");
2851#elif defined(Q_OS_WIN)
2852 return QStringLiteral("windows");
2853
2854#elif defined(Q_OS_QNX)
2855 return QStringLiteral("qnx");
2856
2857#elif defined(Q_OS_ANDROID)
2858 return QStringLiteral("android");
2859
2860#elif defined(Q_OS_IOS)
2861 return QStringLiteral("ios");
2862#elif defined(Q_OS_TVOS)
2863 return QStringLiteral("tvos");
2864#elif defined(Q_OS_WATCHOS)
2865 return QStringLiteral("watchos");
2866#elif defined(Q_OS_MACOS)
2867 // ### Qt6: remove fallback
2868# if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
2869 return QStringLiteral("macos");
2870# else
2871 return QStringLiteral("osx");
2872# endif
2873#elif defined(Q_OS_DARWIN)
2874 return QStringLiteral("darwin");
2875
2876#elif defined(USE_ETC_OS_RELEASE) // Q_OS_UNIX
2877 QUnixOSVersion unixOsVersion;
2878 findUnixOsVersion(v&: unixOsVersion);
2879 if (!unixOsVersion.productType.isEmpty())
2880 return unixOsVersion.productType;
2881#endif
2882 return unknownText();
2883}
2884
2885/*!
2886 \since 5.4
2887
2888 Returns the product version of the operating system in string form. If the
2889 version could not be determined, this function returns "unknown".
2890
2891 It will return the Android, iOS, \macos, Windows full-product
2892 versions on those systems.
2893
2894 Typical returned values are (note: list not exhaustive):
2895 \list
2896 \li "2016.09" (Amazon Linux AMI 2016.09)
2897 \li "7.1" (Android Nougat)
2898 \li "25" (Fedora 25)
2899 \li "10.1" (iOS 10.1)
2900 \li "10.12" (macOS Sierra)
2901 \li "10.0" (tvOS 10)
2902 \li "16.10" (Ubuntu 16.10)
2903 \li "3.1" (watchOS 3.1)
2904 \li "7 SP 1" (Windows 7 Service Pack 1)
2905 \li "8.1" (Windows 8.1)
2906 \li "10" (Windows 10)
2907 \li "Server 2016" (Windows Server 2016)
2908 \endlist
2909
2910 On Linux systems, it will try to determine the distribution version and will
2911 return that. This is also done on Debian/kFreeBSD, so this function will
2912 return Debian version in that case.
2913
2914 In all other Unix-type systems, this function always returns "unknown".
2915
2916 \note The version string returned from this function is not guaranteed to
2917 be orderable. On Linux, the version of
2918 the distribution may jump unexpectedly, please refer to the distribution's
2919 documentation for versioning practices.
2920
2921 \sa kernelType(), kernelVersion(), productType(), prettyProductName()
2922*/
2923QString QSysInfo::productVersion()
2924{
2925#if defined(Q_OS_ANDROID) || defined(Q_OS_DARWIN)
2926 const auto version = QOperatingSystemVersion::current();
2927 return QString::number(version.majorVersion()) + QLatin1Char('.') + QString::number(version.minorVersion());
2928#elif defined(Q_OS_WIN)
2929 const char *version = osVer_helper();
2930 if (version) {
2931 const QLatin1Char spaceChar(' ');
2932 return QString::fromLatin1(version).remove(spaceChar).toLower() + winSp_helper().remove(spaceChar).toLower();
2933 }
2934 // fall through
2935
2936#elif defined(USE_ETC_OS_RELEASE) // Q_OS_UNIX
2937 QUnixOSVersion unixOsVersion;
2938 findUnixOsVersion(v&: unixOsVersion);
2939 if (!unixOsVersion.productVersion.isEmpty())
2940 return unixOsVersion.productVersion;
2941#endif
2942
2943 // fallback
2944 return unknownText();
2945}
2946
2947/*!
2948 \since 5.4
2949
2950 Returns a prettier form of productType() and productVersion(), containing
2951 other tokens like the operating system type, codenames and other
2952 information. The result of this function is suitable for displaying to the
2953 user, but not for long-term storage, as the string may change with updates
2954 to Qt.
2955
2956 If productType() is "unknown", this function will instead use the
2957 kernelType() and kernelVersion() functions.
2958
2959 \sa kernelType(), kernelVersion(), productType(), productVersion()
2960*/
2961QString QSysInfo::prettyProductName()
2962{
2963#if (defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)) || defined(Q_OS_DARWIN) || defined(Q_OS_WIN)
2964 const auto version = QOperatingSystemVersion::current();
2965 const int majorVersion = version.majorVersion();
2966 const QString versionString = QString::number(majorVersion) + QLatin1Char('.')
2967 + QString::number(version.minorVersion());
2968 QString result = version.name() + QLatin1Char(' ');
2969 const char *name = osVer_helper(version);
2970 if (!name)
2971 return result + versionString;
2972 result += QLatin1String(name);
2973# if !defined(Q_OS_WIN) || defined(Q_OS_WINRT)
2974 return result + QLatin1String(" (") + versionString + QLatin1Char(')');
2975# else
2976 // (resembling winver.exe): Windows 10 "Windows 10 Version 1809"
2977 if (majorVersion >= 10) {
2978 const auto releaseId = windows10ReleaseId();
2979 if (!releaseId.isEmpty())
2980 result += QLatin1String(" Version ") + releaseId;
2981 return result;
2982 }
2983 // Windows 7: "Windows 7 Version 6.1 (Build 7601: Service Pack 1)"
2984 result += QLatin1String(" Version ") + versionString + QLatin1String(" (");
2985 const auto build = windows7Build();
2986 if (!build.isEmpty())
2987 result += QLatin1String("Build ") + build;
2988 const auto servicePack = winSp_helper();
2989 if (!servicePack.isEmpty())
2990 result += QLatin1String(": ") + servicePack;
2991 return result + QLatin1Char(')');
2992# endif // Windows
2993#elif defined(Q_OS_HAIKU)
2994 return QLatin1String("Haiku ") + productVersion();
2995#elif defined(Q_OS_UNIX)
2996# ifdef USE_ETC_OS_RELEASE
2997 QUnixOSVersion unixOsVersion;
2998 findUnixOsVersion(v&: unixOsVersion);
2999 if (!unixOsVersion.prettyName.isEmpty())
3000 return unixOsVersion.prettyName;
3001# endif
3002 struct utsname u;
3003 if (uname(name: &u) == 0)
3004 return QString::fromLatin1(str: u.sysname) + QLatin1Char(' ') + QString::fromLatin1(str: u.release);
3005#endif
3006 return unknownText();
3007}
3008
3009#ifndef QT_BOOTSTRAPPED
3010/*!
3011 \since 5.6
3012
3013 Returns this machine's host name, if one is configured. Note that hostnames
3014 are not guaranteed to be globally unique, especially if they were
3015 configured automatically.
3016
3017 This function does not guarantee the returned host name is a Fully
3018 Qualified Domain Name (FQDN). For that, use QHostInfo to resolve the
3019 returned name to an FQDN.
3020
3021 This function returns the same as QHostInfo::localHostName().
3022
3023 \sa QHostInfo::localDomainName, machineUniqueId()
3024 */
3025QString QSysInfo::machineHostName()
3026{
3027 // the hostname can change, so we can't cache it
3028#if defined(Q_OS_LINUX)
3029 // gethostname(3) on Linux just calls uname(2), so do it ourselves
3030 // and avoid a memcpy
3031 struct utsname u;
3032 if (uname(name: &u) == 0)
3033 return QString::fromLocal8Bit(str: u.nodename);
3034 return QString();
3035#else
3036# ifdef Q_OS_WIN
3037 // Important: QtNetwork depends on machineHostName() initializing ws2_32.dll
3038 winsockInit();
3039# endif
3040
3041 char hostName[512];
3042 if (gethostname(hostName, sizeof(hostName)) == -1)
3043 return QString();
3044 hostName[sizeof(hostName) - 1] = '\0';
3045 return QString::fromLocal8Bit(hostName);
3046#endif
3047}
3048#endif // QT_BOOTSTRAPPED
3049
3050enum {
3051 UuidStringLen = sizeof("00000000-0000-0000-0000-000000000000") - 1
3052};
3053
3054/*!
3055 \since 5.11
3056
3057 Returns a unique ID for this machine, if one can be determined. If no
3058 unique ID could be determined, this function returns an empty byte array.
3059 Unlike machineHostName(), the value returned by this function is likely
3060 globally unique.
3061
3062 A unique ID is useful in network operations to identify this machine for an
3063 extended period of time, when the IP address could change or if this
3064 machine could have more than one IP address. For example, the ID could be
3065 used when communicating with a server or when storing device-specific data
3066 in shared network storage.
3067
3068 Note that on some systems, this value will persist across reboots and on
3069 some it will not. Applications should not blindly depend on this fact
3070 without verifying the OS capabilities. In particular, on Linux systems,
3071 this ID is usually permanent and it matches the D-Bus machine ID, except
3072 for nodes without their own storage (replicated nodes).
3073
3074 \sa machineHostName(), bootUniqueId()
3075*/
3076QByteArray QSysInfo::machineUniqueId()
3077{
3078#if defined(Q_OS_DARWIN) && __has_include(<IOKit/IOKitLib.h>)
3079 char uuid[UuidStringLen + 1];
3080 io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"));
3081 QCFString stringRef = (CFStringRef)IORegistryEntryCreateCFProperty(service, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
3082 CFStringGetCString(stringRef, uuid, sizeof(uuid), kCFStringEncodingMacRoman);
3083 return QByteArray(uuid);
3084#elif defined(Q_OS_BSD4) && defined(KERN_HOSTUUID)
3085 char uuid[UuidStringLen + 1];
3086 size_t uuidlen = sizeof(uuid);
3087 int name[] = { CTL_KERN, KERN_HOSTUUID };
3088 if (sysctl(name, sizeof name / sizeof name[0], &uuid, &uuidlen, nullptr, 0) == 0
3089 && uuidlen == sizeof(uuid))
3090 return QByteArray(uuid, uuidlen - 1);
3091#elif defined(Q_OS_UNIX)
3092 // The modern name on Linux is /etc/machine-id, but that path is
3093 // unlikely to exist on non-Linux (non-systemd) systems. The old
3094 // path is more than enough.
3095 static const char fullfilename[] = "/usr/local/var/lib/dbus/machine-id";
3096 const char *firstfilename = fullfilename + sizeof("/usr/local") - 1;
3097 int fd = qt_safe_open(pathname: firstfilename, O_RDONLY);
3098 if (fd == -1 && errno == ENOENT)
3099 fd = qt_safe_open(pathname: fullfilename, O_RDONLY);
3100
3101 if (fd != -1) {
3102 char buffer[32]; // 128 bits, hex-encoded
3103 qint64 len = qt_safe_read(fd, data: buffer, maxlen: sizeof(buffer));
3104 qt_safe_close(fd);
3105
3106 if (len != -1)
3107 return QByteArray(buffer, len);
3108 }
3109#elif defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
3110 // Let's poke at the registry
3111 // ### Qt 6: Use new helpers from qwinregistry.cpp (once bootstrap builds are obsolete)
3112 HKEY key = NULL;
3113 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_READ | KEY_WOW64_64KEY, &key)
3114 == ERROR_SUCCESS) {
3115 wchar_t buffer[UuidStringLen + 1];
3116 DWORD size = sizeof(buffer);
3117 bool ok = (RegQueryValueEx(key, L"MachineGuid", NULL, NULL, (LPBYTE)buffer, &size) ==
3118 ERROR_SUCCESS);
3119 RegCloseKey(key);
3120 if (ok)
3121 return QStringView(buffer, (size - 1) / 2).toLatin1();
3122 }
3123#endif
3124 return QByteArray();
3125}
3126
3127/*!
3128 \since 5.11
3129
3130 Returns a unique ID for this machine's boot, if one can be determined. If
3131 no unique ID could be determined, this function returns an empty byte
3132 array. This value is expected to change after every boot and can be
3133 considered globally unique.
3134
3135 This function is currently only implemented for Linux and Apple operating
3136 systems.
3137
3138 \sa machineUniqueId()
3139*/
3140QByteArray QSysInfo::bootUniqueId()
3141{
3142#ifdef Q_OS_LINUX
3143 // use low-level API here for simplicity
3144 int fd = qt_safe_open(pathname: "/proc/sys/kernel/random/boot_id", O_RDONLY);
3145 if (fd != -1) {
3146 char uuid[UuidStringLen];
3147 qint64 len = qt_safe_read(fd, data: uuid, maxlen: sizeof(uuid));
3148 qt_safe_close(fd);
3149 if (len == UuidStringLen)
3150 return QByteArray(uuid, UuidStringLen);
3151 }
3152#elif defined(Q_OS_DARWIN)
3153 // "kern.bootsessionuuid" is only available by name
3154 char uuid[UuidStringLen + 1];
3155 size_t uuidlen = sizeof(uuid);
3156 if (sysctlbyname("kern.bootsessionuuid", uuid, &uuidlen, nullptr, 0) == 0
3157 && uuidlen == sizeof(uuid))
3158 return QByteArray(uuid, uuidlen - 1);
3159#endif
3160 return QByteArray();
3161};
3162
3163/*!
3164 \macro void Q_ASSERT(bool test)
3165 \relates <QtGlobal>
3166
3167 Prints a warning message containing the source code file name and
3168 line number if \a test is \c false.
3169
3170 Q_ASSERT() is useful for testing pre- and post-conditions
3171 during development. It does nothing if \c QT_NO_DEBUG was defined
3172 during compilation.
3173
3174 Example:
3175
3176 \snippet code/src_corelib_global_qglobal.cpp 17
3177
3178 If \c b is zero, the Q_ASSERT statement will output the following
3179 message using the qFatal() function:
3180
3181 \snippet code/src_corelib_global_qglobal.cpp 18
3182
3183 \sa Q_ASSERT_X(), qFatal(), {Debugging Techniques}
3184*/
3185
3186/*!
3187 \macro void Q_ASSERT_X(bool test, const char *where, const char *what)
3188 \relates <QtGlobal>
3189
3190 Prints the message \a what together with the location \a where,
3191 the source file name and line number if \a test is \c false.
3192
3193 Q_ASSERT_X is useful for testing pre- and post-conditions during
3194 development. It does nothing if \c QT_NO_DEBUG was defined during
3195 compilation.
3196
3197 Example:
3198
3199 \snippet code/src_corelib_global_qglobal.cpp 19
3200
3201 If \c b is zero, the Q_ASSERT_X statement will output the following
3202 message using the qFatal() function:
3203
3204 \snippet code/src_corelib_global_qglobal.cpp 20
3205
3206 \sa Q_ASSERT(), qFatal(), {Debugging Techniques}
3207*/
3208
3209/*!
3210 \macro void Q_ASSUME(bool expr)
3211 \relates <QtGlobal>
3212 \since 5.0
3213
3214 Causes the compiler to assume that \a expr is \c true. This macro is useful
3215 for improving code generation, by providing the compiler with hints about
3216 conditions that it would not otherwise know about. However, there is no
3217 guarantee that the compiler will actually use those hints.
3218
3219 This macro could be considered a "lighter" version of \l{Q_ASSERT()}. While
3220 Q_ASSERT will abort the program's execution if the condition is \c false,
3221 Q_ASSUME will tell the compiler not to generate code for those conditions.
3222 Therefore, it is important that the assumptions always hold, otherwise
3223 undefined behaviour may occur.
3224
3225 If \a expr is a constantly \c false condition, Q_ASSUME will tell the compiler
3226 that the current code execution cannot be reached. That is, Q_ASSUME(false)
3227 is equivalent to Q_UNREACHABLE().
3228
3229 In debug builds the condition is enforced by an assert to facilitate debugging.
3230
3231 \note Q_LIKELY() tells the compiler that the expression is likely, but not
3232 the only possibility. Q_ASSUME tells the compiler that it is the only
3233 possibility.
3234
3235 \sa Q_ASSERT(), Q_UNREACHABLE(), Q_LIKELY()
3236*/
3237
3238/*!
3239 \macro void Q_UNREACHABLE()
3240 \relates <QtGlobal>
3241 \since 5.0
3242
3243 Tells the compiler that the current point cannot be reached by any
3244 execution, so it may optimize any code paths leading here as dead code, as
3245 well as code continuing from here.
3246
3247 This macro is useful to mark impossible conditions. For example, given the
3248 following enum:
3249
3250 \snippet code/src_corelib_global_qglobal.cpp qunreachable-enum
3251
3252 One can write a switch table like so:
3253
3254 \snippet code/src_corelib_global_qglobal.cpp qunreachable-switch
3255
3256 The advantage of inserting Q_UNREACHABLE() at that point is that the
3257 compiler is told not to generate code for a shape variable containing that
3258 value. If the macro is missing, the compiler will still generate the
3259 necessary comparisons for that value. If the case label were removed, some
3260 compilers could produce a warning that some enum values were not checked.
3261
3262 By using this macro in impossible conditions, code coverage may be improved
3263 as dead code paths may be eliminated.
3264
3265 In debug builds the condition is enforced by an assert to facilitate debugging.
3266
3267 \sa Q_ASSERT(), Q_ASSUME(), qFatal()
3268*/
3269
3270/*!
3271 \macro void Q_FALLTHROUGH()
3272 \relates <QtGlobal>
3273 \since 5.8
3274
3275 Can be used in switch statements at the end of case block to tell the compiler
3276 and other developers that that the lack of a break statement is intentional.
3277
3278 This is useful since a missing break statement is often a bug, and some
3279 compilers can be configured to emit warnings when one is not found.
3280
3281 \sa Q_UNREACHABLE()
3282*/
3283
3284/*!
3285 \macro void Q_CHECK_PTR(void *pointer)
3286 \relates <QtGlobal>
3287
3288 If \a pointer is \nullptr, prints a message containing the source
3289 code's file name and line number, saying that the program ran out
3290 of memory and aborts program execution. It throws \c std::bad_alloc instead
3291 if exceptions are enabled.
3292
3293 Q_CHECK_PTR does nothing if \c QT_NO_DEBUG and \c QT_NO_EXCEPTIONS were
3294 defined during compilation. Therefore you must not use Q_CHECK_PTR to check
3295 for successful memory allocations because the check will be disabled in
3296 some cases.
3297
3298 Example:
3299
3300 \snippet code/src_corelib_global_qglobal.cpp 21
3301
3302 \sa qWarning(), {Debugging Techniques}
3303*/
3304
3305/*!
3306 \fn template <typename T> T *q_check_ptr(T *p)
3307 \relates <QtGlobal>
3308
3309 Uses Q_CHECK_PTR on \a p, then returns \a p.
3310
3311 This can be used as an inline version of Q_CHECK_PTR.
3312*/
3313
3314/*!
3315 \macro const char* Q_FUNC_INFO()
3316 \relates <QtGlobal>
3317
3318 Expands to a string that describe the function the macro resides in. How this string looks
3319 more specifically is compiler dependent. With GNU GCC it is typically the function signature,
3320 while with other compilers it might be the line and column number.
3321
3322 Q_FUNC_INFO can be conveniently used with qDebug(). For example, this function:
3323
3324 \snippet code/src_corelib_global_qglobal.cpp 22
3325
3326 when instantiated with the integer type, will with the GCC compiler produce:
3327
3328 \tt{const TInputType& myMin(const TInputType&, const TInputType&) [with TInputType = int] was called with value1: 3 value2: 4}
3329
3330 If this macro is used outside a function, the behavior is undefined.
3331 */
3332
3333/*!
3334 \internal
3335 The Q_CHECK_PTR macro calls this function if an allocation check
3336 fails.
3337*/
3338void qt_check_pointer(const char *n, int l) noexcept
3339{
3340 // make separate printing calls so that the first one may flush;
3341 // the second one could want to allocate memory (fputs prints a
3342 // newline and stderr auto-flushes).
3343 fputs(s: "Out of memory", stderr);
3344 fprintf(stderr, format: " in %s, line %d\n", n, l);
3345
3346 std::terminate();
3347}
3348
3349/*
3350 \internal
3351 Allows you to throw an exception without including <new>
3352 Called internally from Q_CHECK_PTR on certain OS combinations
3353*/
3354void qBadAlloc()
3355{
3356 QT_THROW(std::bad_alloc());
3357}
3358
3359#ifndef QT_NO_EXCEPTIONS
3360/*
3361 \internal
3362 Allows you to call std::terminate() without including <exception>.
3363 Called internally from QT_TERMINATE_ON_EXCEPTION
3364*/
3365Q_NORETURN void qTerminate() noexcept
3366{
3367 std::terminate();
3368}
3369#endif
3370
3371/*
3372 The Q_ASSERT macro calls this function when the test fails.
3373*/
3374void qt_assert(const char *assertion, const char *file, int line) noexcept
3375{
3376 QMessageLogger(file, line, nullptr).fatal(msg: "ASSERT: \"%s\" in file %s, line %d", assertion, file, line);
3377}
3378
3379/*
3380 The Q_ASSERT_X macro calls this function when the test fails.
3381*/
3382void qt_assert_x(const char *where, const char *what, const char *file, int line) noexcept
3383{
3384 QMessageLogger(file, line, nullptr).fatal(msg: "ASSERT failure in %s: \"%s\", file %s, line %d", where, what, file, line);
3385}
3386
3387
3388/*
3389 Dijkstra's bisection algorithm to find the square root of an integer.
3390 Deliberately not exported as part of the Qt API, but used in both
3391 qsimplerichtext.cpp and qgfxraster_qws.cpp
3392*/
3393Q_CORE_EXPORT Q_DECL_CONST_FUNCTION unsigned int qt_int_sqrt(unsigned int n)
3394{
3395 // n must be in the range 0...UINT_MAX/2-1
3396 if (n >= (UINT_MAX>>2)) {
3397 unsigned int r = 2 * qt_int_sqrt(n: n / 4);
3398 unsigned int r2 = r + 1;
3399 return (n >= r2 * r2) ? r2 : r;
3400 }
3401 uint h, p= 0, q= 1, r= n;
3402 while (q <= n)
3403 q <<= 2;
3404 while (q != 1) {
3405 q >>= 2;
3406 h= p + q;
3407 p >>= 1;
3408 if (r >= h) {
3409 p += q;
3410 r -= h;
3411 }
3412 }
3413 return p;
3414}
3415
3416void *qMemCopy(void *dest, const void *src, size_t n) { return memcpy(dest: dest, src: src, n: n); }
3417void *qMemSet(void *dest, int c, size_t n) { return memset(s: dest, c: c, n: n); }
3418
3419// In the C runtime on all platforms access to the environment is not thread-safe. We
3420// add thread-safety for the Qt wrappers.
3421static QBasicMutex environmentMutex;
3422
3423/*
3424 Wraps tzset(), which accesses the environment, so should only be called while
3425 we hold the lock on the environment mutex.
3426*/
3427void qTzSet()
3428{
3429 const auto locker = qt_scoped_lock(mutex&: environmentMutex);
3430#if defined(Q_OS_WIN)
3431 _tzset();
3432#else
3433 tzset();
3434#endif // Q_OS_WIN
3435}
3436
3437/*
3438 Wrap mktime(), which is specified to behave as if it called tzset(), hence
3439 shares its implicit environment-dependence.
3440*/
3441time_t qMkTime(struct tm *when)
3442{
3443 const auto locker = qt_scoped_lock(mutex&: environmentMutex);
3444 return mktime(tp: when);
3445}
3446
3447// Also specified to behave as if they call tzset():
3448// localtime() -- but not localtime_r(), which we use when threaded
3449// strftime() -- not used (except in tests)
3450
3451/*!
3452 \relates <QtGlobal>
3453 \threadsafe
3454
3455 Returns the value of the environment variable with name \a varName as a
3456 QByteArray. If no variable by that name is found in the environment, this
3457 function returns a default-constructed QByteArray.
3458
3459 The Qt environment manipulation functions are thread-safe, but this
3460 requires that the C library equivalent functions like getenv and putenv are
3461 not directly called.
3462
3463 To convert the data to a QString use QString::fromLocal8Bit().
3464
3465 \note on desktop Windows, qgetenv() may produce data loss if the
3466 original string contains Unicode characters not representable in the
3467 ANSI encoding. Use qEnvironmentVariable() instead.
3468 On Unix systems, this function is lossless.
3469
3470 \sa qputenv(), qEnvironmentVariable(), qEnvironmentVariableIsSet(),
3471 qEnvironmentVariableIsEmpty()
3472*/
3473QByteArray qgetenv(const char *varName)
3474{
3475 const auto locker = qt_scoped_lock(mutex&: environmentMutex);
3476#ifdef Q_CC_MSVC
3477 size_t requiredSize = 0;
3478 QByteArray buffer;
3479 getenv_s(&requiredSize, 0, 0, varName);
3480 if (requiredSize == 0)
3481 return buffer;
3482 buffer.resize(int(requiredSize));
3483 getenv_s(&requiredSize, buffer.data(), requiredSize, varName);
3484 // requiredSize includes the terminating null, which we don't want.
3485 Q_ASSERT(buffer.endsWith('\0'));
3486 buffer.chop(1);
3487 return buffer;
3488#else
3489 return QByteArray(::getenv(name: varName));
3490#endif
3491}
3492
3493
3494/*!
3495 \fn QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
3496 \fn QString qEnvironmentVariable(const char *varName)
3497
3498 \relates <QtGlobal>
3499 \since 5.10
3500
3501 These functions return the value of the environment variable, \a varName, as a
3502 QString. If no variable \a varName is found in the environment and \a defaultValue
3503 is provided, \a defaultValue is returned. Otherwise QString() is returned.
3504
3505 The Qt environment manipulation functions are thread-safe, but this
3506 requires that the C library equivalent functions like getenv and putenv are
3507 not directly called.
3508
3509 The following table describes how to choose between qgetenv() and
3510 qEnvironmentVariable():
3511 \table
3512 \header \li Condition \li Recommendation
3513 \row
3514 \li Variable contains file paths or user text
3515 \li qEnvironmentVariable()
3516 \row
3517 \li Windows-specific code
3518 \li qEnvironmentVariable()
3519 \row
3520 \li Unix-specific code, destination variable is not QString and/or is
3521 used to interface with non-Qt APIs
3522 \li qgetenv()
3523 \row
3524 \li Destination variable is a QString
3525 \li qEnvironmentVariable()
3526 \row
3527 \li Destination variable is a QByteArray or std::string
3528 \li qgetenv()
3529 \endtable
3530
3531 \note on Unix systems, this function may produce data loss if the original
3532 string contains arbitrary binary data that cannot be decoded by the locale
3533 codec. Use qgetenv() instead for that case. On Windows, this function is
3534 lossless.
3535
3536 \note the variable name \a varName must contain only US-ASCII characters.
3537
3538 \sa qputenv(), qgetenv(), qEnvironmentVariableIsSet(), qEnvironmentVariableIsEmpty()
3539*/
3540QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
3541{
3542#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
3543 const auto locker = qt_scoped_lock(environmentMutex);
3544 QVarLengthArray<wchar_t, 32> wname(int(strlen(varName)) + 1);
3545 for (int i = 0; i < wname.size(); ++i) // wname.size() is correct: will copy terminating null
3546 wname[i] = uchar(varName[i]);
3547 size_t requiredSize = 0;
3548 QString buffer;
3549 _wgetenv_s(&requiredSize, 0, 0, wname.data());
3550 if (requiredSize == 0)
3551 return defaultValue;
3552 buffer.resize(int(requiredSize));
3553 _wgetenv_s(&requiredSize, reinterpret_cast<wchar_t *>(buffer.data()), requiredSize,
3554 wname.data());
3555 // requiredSize includes the terminating null, which we don't want.
3556 Q_ASSERT(buffer.endsWith(QLatin1Char('\0')));
3557 buffer.chop(1);
3558 return buffer;
3559#else
3560 QByteArray value = qgetenv(varName);
3561 if (value.isNull())
3562 return defaultValue;
3563// duplicated in qfile.h (QFile::decodeName)
3564#if defined(Q_OS_DARWIN)
3565 return QString::fromUtf8(value).normalized(QString::NormalizationForm_C);
3566#else // other Unix
3567 return QString::fromLocal8Bit(str: value);
3568#endif
3569#endif
3570}
3571
3572QString qEnvironmentVariable(const char *varName)
3573{
3574 return qEnvironmentVariable(varName, defaultValue: QString());
3575}
3576
3577/*!
3578 \relates <QtGlobal>
3579 \since 5.1
3580
3581 Returns whether the environment variable \a varName is empty.
3582
3583 Equivalent to
3584 \snippet code/src_corelib_global_qglobal.cpp is-empty
3585 except that it's potentially much faster, and can't throw exceptions.
3586
3587 \sa qgetenv(), qEnvironmentVariable(), qEnvironmentVariableIsSet()
3588*/
3589bool qEnvironmentVariableIsEmpty(const char *varName) noexcept
3590{
3591 const auto locker = qt_scoped_lock(mutex&: environmentMutex);
3592#ifdef Q_CC_MSVC
3593 // we provide a buffer that can only hold the empty string, so
3594 // when the env.var isn't empty, we'll get an ERANGE error (buffer
3595 // too small):
3596 size_t dummy;
3597 char buffer = '\0';
3598 return getenv_s(&dummy, &buffer, 1, varName) != ERANGE;
3599#else
3600 const char * const value = ::getenv(name: varName);
3601 return !value || !*value;
3602#endif
3603}
3604
3605/*!
3606 \relates <QtGlobal>
3607 \since 5.5
3608
3609 Returns the numerical value of the environment variable \a varName.
3610 If \a ok is not null, sets \c{*ok} to \c true or \c false depending
3611 on the success of the conversion.
3612
3613 Equivalent to
3614 \snippet code/src_corelib_global_qglobal.cpp to-int
3615 except that it's much faster, and can't throw exceptions.
3616
3617 \note there's a limit on the length of the value, which is sufficient for
3618 all valid values of int, not counting leading zeroes or spaces. Values that
3619 are too long will either be truncated or this function will set \a ok to \c
3620 false.
3621
3622 \sa qgetenv(), qEnvironmentVariable(), qEnvironmentVariableIsSet()
3623*/
3624int qEnvironmentVariableIntValue(const char *varName, bool *ok) noexcept
3625{
3626 static const int NumBinaryDigitsPerOctalDigit = 3;
3627 static const int MaxDigitsForOctalInt =
3628 (std::numeric_limits<uint>::digits + NumBinaryDigitsPerOctalDigit - 1) / NumBinaryDigitsPerOctalDigit;
3629
3630 const auto locker = qt_scoped_lock(mutex&: environmentMutex);
3631#ifdef Q_CC_MSVC
3632 // we provide a buffer that can hold any int value:
3633 char buffer[MaxDigitsForOctalInt + 2]; // +1 for NUL +1 for optional '-'
3634 size_t dummy;
3635 if (getenv_s(&dummy, buffer, sizeof buffer, varName) != 0) {
3636 if (ok)
3637 *ok = false;
3638 return 0;
3639 }
3640#else
3641 const char * const buffer = ::getenv(name: varName);
3642 if (!buffer || strlen(s: buffer) > MaxDigitsForOctalInt + 2) {
3643 if (ok)
3644 *ok = false;
3645 return 0;
3646 }
3647#endif
3648 bool ok_ = true;
3649 const char *endptr;
3650 const qlonglong value = qstrtoll(nptr: buffer, endptr: &endptr, base: 0, ok: &ok_);
3651
3652 // Keep the following checks in sync with QByteArray::toInt()
3653 if (!ok_) {
3654 if (ok)
3655 *ok = false;
3656 return 0;
3657 }
3658
3659 if (*endptr != '\0') {
3660 while (ascii_isspace(c: *endptr))
3661 ++endptr;
3662 }
3663
3664 if (*endptr != '\0') {
3665 // we stopped at a non-digit character after converting some digits
3666 if (ok)
3667 *ok = false;
3668 return 0;
3669 }
3670
3671 if (int(value) != value) {
3672 if (ok)
3673 *ok = false;
3674 return 0;
3675 } else if (ok) {
3676 *ok = ok_;
3677 }
3678 return int(value);
3679}
3680
3681/*!
3682 \relates <QtGlobal>
3683 \since 5.1
3684
3685 Returns whether the environment variable \a varName is set.
3686
3687 Equivalent to
3688 \snippet code/src_corelib_global_qglobal.cpp is-null
3689 except that it's potentially much faster, and can't throw exceptions.
3690
3691 \sa qgetenv(), qEnvironmentVariable(), qEnvironmentVariableIsEmpty()
3692*/
3693bool qEnvironmentVariableIsSet(const char *varName) noexcept
3694{
3695 const auto locker = qt_scoped_lock(mutex&: environmentMutex);
3696#ifdef Q_CC_MSVC
3697 size_t requiredSize = 0;
3698 (void)getenv_s(&requiredSize, 0, 0, varName);
3699 return requiredSize != 0;
3700#else
3701 return ::getenv(name: varName) != nullptr;
3702#endif
3703}
3704
3705/*!
3706 \relates <QtGlobal>
3707
3708 This function sets the \a value of the environment variable named
3709 \a varName. It will create the variable if it does not exist. It
3710 returns 0 if the variable could not be set.
3711
3712 Calling qputenv with an empty value removes the environment variable on
3713 Windows, and makes it set (but empty) on Unix. Prefer using qunsetenv()
3714 for fully portable behavior.
3715
3716 \note qputenv() was introduced because putenv() from the standard
3717 C library was deprecated in VC2005 (and later versions). qputenv()
3718 uses the replacement function in VC, and calls the standard C
3719 library's implementation on all other platforms.
3720
3721 \sa qgetenv(), qEnvironmentVariable()
3722*/
3723bool qputenv(const char *varName, const QByteArray& value)
3724{
3725 const auto locker = qt_scoped_lock(mutex&: environmentMutex);
3726#if defined(Q_CC_MSVC)
3727 return _putenv_s(varName, value.constData()) == 0;
3728#elif (defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L) || defined(Q_OS_HAIKU)
3729 // POSIX.1-2001 has setenv
3730 return setenv(name: varName, value: value.constData(), replace: true) == 0;
3731#else
3732 QByteArray buffer(varName);
3733 buffer += '=';
3734 buffer += value;
3735 char* envVar = qstrdup(buffer.constData());
3736 int result = putenv(envVar);
3737 if (result != 0) // error. we have to delete the string.
3738 delete[] envVar;
3739 return result == 0;
3740#endif
3741}
3742
3743/*!
3744 \relates <QtGlobal>
3745
3746 This function deletes the variable \a varName from the environment.
3747
3748 Returns \c true on success.
3749
3750 \since 5.1
3751
3752 \sa qputenv(), qgetenv(), qEnvironmentVariable()
3753*/
3754bool qunsetenv(const char *varName)
3755{
3756 const auto locker = qt_scoped_lock(mutex&: environmentMutex);
3757#if defined(Q_CC_MSVC)
3758 return _putenv_s(varName, "") == 0;
3759#elif (defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L) || defined(Q_OS_BSD4) || defined(Q_OS_HAIKU)
3760 // POSIX.1-2001, BSD and Haiku have unsetenv
3761 return unsetenv(name: varName) == 0;
3762#elif defined(Q_CC_MINGW)
3763 // On mingw, putenv("var=") removes "var" from the environment
3764 QByteArray buffer(varName);
3765 buffer += '=';
3766 return putenv(buffer.constData()) == 0;
3767#else
3768 // Fallback to putenv("var=") which will insert an empty var into the
3769 // environment and leak it
3770 QByteArray buffer(varName);
3771 buffer += '=';
3772 char *envVar = qstrdup(buffer.constData());
3773 return putenv(envVar) == 0;
3774#endif
3775}
3776
3777/*!
3778 \macro forever
3779 \relates <QtGlobal>
3780
3781 This macro is provided for convenience for writing infinite
3782 loops.
3783
3784 Example:
3785
3786 \snippet code/src_corelib_global_qglobal.cpp 31
3787
3788 It is equivalent to \c{for (;;)}.
3789
3790 If you're worried about namespace pollution, you can disable this
3791 macro by adding the following line to your \c .pro file:
3792
3793 \snippet code/src_corelib_global_qglobal.cpp 32
3794
3795 \sa Q_FOREVER
3796*/
3797
3798/*!
3799 \macro Q_FOREVER
3800 \relates <QtGlobal>
3801
3802 Same as \l{forever}.
3803
3804 This macro is available even when \c no_keywords is specified
3805 using the \c .pro file's \c CONFIG variable.
3806
3807 \sa foreach()
3808*/
3809
3810/*!
3811 \macro foreach(variable, container)
3812 \relates <QtGlobal>
3813
3814 This macro is used to implement Qt's \c foreach loop. The \a
3815 variable parameter is a variable name or variable definition; the
3816 \a container parameter is a Qt container whose value type
3817 corresponds to the type of the variable. See \l{The foreach
3818 Keyword} for details.
3819
3820 If you're worried about namespace pollution, you can disable this
3821 macro by adding the following line to your \c .pro file:
3822
3823 \snippet code/src_corelib_global_qglobal.cpp 33
3824
3825 \note Since Qt 5.7, the use of this macro is discouraged. It will
3826 be removed in a future version of Qt. Please use C++11 range-for,
3827 possibly with qAsConst(), as needed.
3828
3829 \sa qAsConst()
3830*/
3831
3832/*!
3833 \macro Q_FOREACH(variable, container)
3834 \relates <QtGlobal>
3835
3836 Same as foreach(\a variable, \a container).
3837
3838 This macro is available even when \c no_keywords is specified
3839 using the \c .pro file's \c CONFIG variable.
3840
3841 \note Since Qt 5.7, the use of this macro is discouraged. It will
3842 be removed in a future version of Qt. Please use C++11 range-for,
3843 possibly with qAsConst(), as needed.
3844
3845 \sa qAsConst()
3846*/
3847
3848/*!
3849 \fn template <typename T> typename std::add_const<T>::type &qAsConst(T &t)
3850 \relates <QtGlobal>
3851 \since 5.7
3852
3853 Returns \a t cast to \c{const T}.
3854
3855 This function is a Qt implementation of C++17's std::as_const(),
3856 a cast function like std::move(). But while std::move() turns
3857 lvalues into rvalues, this function turns non-const lvalues into
3858 const lvalues. Like std::as_const(), it doesn't work on rvalues,
3859 because it cannot be efficiently implemented for rvalues without
3860 leaving dangling references.
3861
3862 Its main use in Qt is to prevent implicitly-shared Qt containers
3863 from detaching:
3864 \snippet code/src_corelib_global_qglobal.cpp as-const-0
3865
3866 Of course, in this case, you could (and probably should) have declared
3867 \c s as \c const in the first place:
3868 \snippet code/src_corelib_global_qglobal.cpp as-const-1
3869 but often that is not easily possible.
3870
3871 It is important to note that qAsConst() does not copy its argument,
3872 it just performs a \c{const_cast<const T&>(t)}. This is also the reason
3873 why it is designed to fail for rvalues: The returned reference would go
3874 stale too soon. So while this works (but detaches the returned object):
3875 \snippet code/src_corelib_global_qglobal.cpp as-const-2
3876
3877 this would not:
3878 \snippet code/src_corelib_global_qglobal.cpp as-const-3
3879
3880 To prevent this construct from compiling (and failing at runtime), qAsConst() has
3881 a second, deleted, overload which binds to rvalues.
3882*/
3883
3884/*!
3885 \fn template <typename T> void qAsConst(const T &&t)
3886 \relates <QtGlobal>
3887 \since 5.7
3888 \overload
3889
3890 This overload is deleted to prevent a dangling reference in code like
3891 \snippet code/src_corelib_global_qglobal.cpp as-const-4
3892*/
3893
3894/*!
3895 \fn template <typename T, typename U = T> T qExchange(T &obj, U &&newValue)
3896 \relates <QtGlobal>
3897 \since 5.14
3898
3899 Replaces the value of \a obj with \a newValue and returns the old value of \a obj.
3900
3901 This is Qt's implementation of std::exchange(). It differs from std::exchange()
3902 only in that it is \c constexpr already in C++14, and available on all supported
3903 compilers.
3904
3905 Here is how to use qExchange() to implement move constructors:
3906 \code
3907 MyClass(MyClass &&other)
3908 : m_pointer{qExchange(other.m_pointer, nullptr)},
3909 m_int{qExchange(other.m_int, 0)},
3910 m_vector{std::move(other.m_vector)},
3911 ...
3912 \endcode
3913
3914 For members of class type, we can use std::move(), as their move-constructor will
3915 do the right thing. But for scalar types such as raw pointers or integer type, move
3916 is the same as copy, which, particularly for pointers, is not what we expect. So, we
3917 cannot use std::move() for such types, but we can use std::exchange()/qExchange() to
3918 make sure the source object's member is already reset by the time we get to the
3919 initialization of our next data member, which might come in handy if the constructor
3920 exits with an exception.
3921
3922 Here is how to use qExchange() to write a loop that consumes the collection it
3923 iterates over:
3924 \code
3925 for (auto &e : qExchange(collection, {})
3926 doSomethingWith(e);
3927 \endcode
3928
3929 Which is equivalent to the following, much more verbose code:
3930 \code
3931 {
3932 auto tmp = std::move(collection);
3933 collection = {}; // or collection.clear()
3934 for (auto &e : tmp)
3935 doSomethingWith(e);
3936 } // destroys 'tmp'
3937 \endcode
3938
3939 This is perfectly safe, as the for-loop keeps the result of qExchange() alive for as
3940 long as the loop runs, saving the declaration of a temporary variable. Be aware, though,
3941 that qExchange() returns a non-const object, so Qt containers may detach.
3942*/
3943
3944/*!
3945 \macro QT_TR_NOOP(sourceText)
3946 \relates <QtGlobal>
3947
3948 Marks the UTF-8 encoded string literal \a sourceText for delayed
3949 translation in the current context (class).
3950
3951 The macro tells lupdate to collect the string, and expands to
3952 \a sourceText itself.
3953
3954 Example:
3955
3956 \snippet code/src_corelib_global_qglobal.cpp 34
3957
3958 The macro QT_TR_NOOP_UTF8() is identical and obsolete; this applies
3959 to all other _UTF8 macros as well.
3960
3961 \sa QT_TRANSLATE_NOOP(), {Internationalization with Qt}
3962*/
3963
3964/*!
3965 \macro QT_TRANSLATE_NOOP(context, sourceText)
3966 \relates <QtGlobal>
3967
3968 Marks the UTF-8 encoded string literal \a sourceText for delayed
3969 translation in the given \a context. The \a context is typically
3970 a class name and also needs to be specified as a string literal.
3971
3972 The macro tells lupdate to collect the string, and expands to
3973 \a sourceText itself.
3974
3975 Example:
3976
3977 \snippet code/src_corelib_global_qglobal.cpp 35
3978
3979 \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP3(), {Internationalization with Qt}
3980*/
3981
3982/*!
3983 \macro QT_TRANSLATE_NOOP3(context, sourceText, disambiguation)
3984 \relates <QtGlobal>
3985 \since 4.4
3986
3987 Marks the UTF-8 encoded string literal \a sourceText for delayed
3988 translation in the given \a context with the given \a disambiguation.
3989 The \a context is typically a class and also needs to be specified
3990 as a string literal. The string literal \a disambiguation should be
3991 a short semantic tag to tell apart otherwise identical strings.
3992
3993 The macro tells lupdate to collect the string, and expands to an
3994 anonymous struct of the two string literals passed as \a sourceText
3995 and \a disambiguation.
3996
3997 Example:
3998
3999 \snippet code/src_corelib_global_qglobal.cpp 36
4000
4001 \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP(), {Internationalization with Qt}
4002*/
4003
4004/*!
4005 \macro QT_TR_N_NOOP(sourceText)
4006 \relates <QtGlobal>
4007 \since 5.12
4008
4009 Marks the UTF-8 encoded string literal \a sourceText for numerator
4010 dependent delayed translation in the current context (class).
4011
4012 The macro tells lupdate to collect the string, and expands to
4013 \a sourceText itself.
4014
4015 The macro expands to \a sourceText.
4016
4017 Example:
4018
4019 \snippet code/src_corelib_global_qglobal.cpp qttrnnoop
4020
4021 \sa QT_TR_NOOP, {Internationalization with Qt}
4022*/
4023
4024/*!
4025 \macro QT_TRANSLATE_N_NOOP(context, sourceText)
4026 \relates <QtGlobal>
4027 \since 5.12
4028
4029 Marks the UTF-8 encoded string literal \a sourceText for numerator
4030 dependent delayed translation in the given \a context.
4031 The \a context is typically a class name and also needs to be
4032 specified as a string literal.
4033
4034 The macro tells lupdate to collect the string, and expands to
4035 \a sourceText itself.
4036
4037 Example:
4038
4039 \snippet code/src_corelib_global_qglobal.cpp qttranslatennoop
4040
4041 \sa QT_TRANSLATE_NOOP(), QT_TRANSLATE_N_NOOP3(),
4042 {Internationalization with Qt}
4043*/
4044
4045/*!
4046 \macro QT_TRANSLATE_N_NOOP3(context, sourceText, comment)
4047 \relates <QtGlobal>
4048 \since 5.12
4049
4050 Marks the UTF-8 encoded string literal \a sourceText for numerator
4051 dependent delayed translation in the given \a context with the given
4052 \a comment.
4053 The \a context is typically a class and also needs to be specified
4054 as a string literal. The string literal \a comment should be
4055 a short semantic tag to tell apart otherwise identical strings.
4056
4057 The macro tells lupdate to collect the string, and expands to an
4058 anonymous struct of the two string literals passed as \a sourceText
4059 and \a comment.
4060
4061 Example:
4062
4063 \snippet code/src_corelib_global_qglobal.cpp qttranslatennoop3
4064
4065 \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP(), QT_TRANSLATE_NOOP3(),
4066 {Internationalization with Qt}
4067*/
4068
4069/*!
4070 \fn QString qtTrId(const char *id, int n = -1)
4071 \relates <QtGlobal>
4072 \reentrant
4073 \since 4.6
4074
4075 \brief The qtTrId function finds and returns a translated string.
4076
4077 Returns a translated string identified by \a id.
4078 If no matching string is found, the id itself is returned. This
4079 should not happen under normal conditions.
4080
4081 If \a n >= 0, all occurrences of \c %n in the resulting string
4082 are replaced with a decimal representation of \a n. In addition,
4083 depending on \a n's value, the translation text may vary.
4084
4085 Meta data and comments can be passed as documented for QObject::tr().
4086 In addition, it is possible to supply a source string template like that:
4087
4088 \tt{//% <C string>}
4089
4090 or
4091
4092 \tt{\\begincomment% <C string> \\endcomment}
4093
4094 Example:
4095
4096 \snippet code/src_corelib_global_qglobal.cpp qttrid
4097
4098 Creating QM files suitable for use with this function requires passing
4099 the \c -idbased option to the \c lrelease tool.
4100
4101 \warning This method is reentrant only if all translators are
4102 installed \e before calling this method. Installing or removing
4103 translators while performing translations is not supported. Doing
4104 so will probably result in crashes or other undesirable behavior.
4105
4106 \sa QObject::tr(), QCoreApplication::translate(), {Internationalization with Qt}
4107*/
4108
4109/*!
4110 \macro QT_TRID_NOOP(id)
4111 \relates <QtGlobal>
4112 \since 4.6
4113
4114 \brief The QT_TRID_NOOP macro marks an id for dynamic translation.
4115
4116 The only purpose of this macro is to provide an anchor for attaching
4117 meta data like to qtTrId().
4118
4119 The macro expands to \a id.
4120
4121 Example:
4122
4123 \snippet code/src_corelib_global_qglobal.cpp qttrid_noop
4124
4125 \sa qtTrId(), {Internationalization with Qt}
4126*/
4127
4128/*!
4129 \macro Q_LIKELY(expr)
4130 \relates <QtGlobal>
4131 \since 4.8
4132
4133 \brief Hints to the compiler that the enclosed condition, \a expr, is
4134 likely to evaluate to \c true.
4135
4136 Use of this macro can help the compiler to optimize the code.
4137
4138 Example:
4139
4140 \snippet code/src_corelib_global_qglobal.cpp qlikely
4141
4142 \sa Q_UNLIKELY()
4143*/
4144
4145/*!
4146 \macro Q_UNLIKELY(expr)
4147 \relates <QtGlobal>
4148 \since 4.8
4149
4150 \brief Hints to the compiler that the enclosed condition, \a expr, is
4151 likely to evaluate to \c false.
4152
4153 Use of this macro can help the compiler to optimize the code.
4154
4155 Example:
4156
4157 \snippet code/src_corelib_global_qglobal.cpp qunlikely
4158
4159 \sa Q_LIKELY()
4160*/
4161
4162/*!
4163 \macro QT_POINTER_SIZE
4164 \relates <QtGlobal>
4165
4166 Expands to the size of a pointer in bytes (4 or 8). This is
4167 equivalent to \c sizeof(void *) but can be used in a preprocessor
4168 directive.
4169*/
4170
4171/*!
4172 \macro const char *qPrintable(const QString &str)
4173 \relates <QtGlobal>
4174
4175 Returns \a str as a \c{const char *}. This is equivalent to
4176 \a{str}.toLocal8Bit().constData().
4177
4178 The char pointer will be invalid after the statement in which
4179 qPrintable() is used. This is because the array returned by
4180 QString::toLocal8Bit() will fall out of scope.
4181
4182 \note qDebug(), qInfo(), qWarning(), qCritical(), qFatal() expect
4183 %s arguments to be UTF-8 encoded, while qPrintable() converts to
4184 local 8-bit encoding. Therefore qUtf8Printable() should be used
4185 for logging strings instead of qPrintable().
4186
4187 \sa qUtf8Printable()
4188*/
4189
4190/*!
4191 \macro const char *qUtf8Printable(const QString &str)
4192 \relates <QtGlobal>
4193 \since 5.4
4194
4195 Returns \a str as a \c{const char *}. This is equivalent to
4196 \a{str}.toUtf8().constData().
4197
4198 The char pointer will be invalid after the statement in which
4199 qUtf8Printable() is used. This is because the array returned by
4200 QString::toUtf8() will fall out of scope.
4201
4202 Example:
4203
4204 \snippet code/src_corelib_global_qglobal.cpp 37
4205
4206 \sa qPrintable(), qDebug(), qInfo(), qWarning(), qCritical(), qFatal()
4207*/
4208
4209/*!
4210 \macro const wchar_t *qUtf16Printable(const QString &str)
4211 \relates <QtGlobal>
4212 \since 5.7
4213
4214 Returns \a str as a \c{const ushort *}, but cast to a \c{const wchar_t *}
4215 to avoid warnings. This is equivalent to \a{str}.utf16() plus some casting.
4216
4217 The only useful thing you can do with the return value of this macro is to
4218 pass it to QString::asprintf() for use in a \c{%ls} conversion. In particular,
4219 the return value is \e{not} a valid \c{const wchar_t*}!
4220
4221 In general, the pointer will be invalid after the statement in which
4222 qUtf16Printable() is used. This is because the pointer may have been
4223 obtained from a temporary expression, which will fall out of scope.
4224
4225 Example:
4226
4227 \snippet code/src_corelib_global_qglobal.cpp qUtf16Printable
4228
4229 \sa qPrintable(), qDebug(), qInfo(), qWarning(), qCritical(), qFatal()
4230*/
4231
4232/*!
4233 \macro Q_DECLARE_TYPEINFO(Type, Flags)
4234 \relates <QtGlobal>
4235
4236 You can use this macro to specify information about a custom type
4237 \a Type. With accurate type information, Qt's \l{Container Classes}
4238 {generic containers} can choose appropriate storage methods and
4239 algorithms.
4240
4241 \a Flags can be one of the following:
4242
4243 \list
4244 \li \c Q_PRIMITIVE_TYPE specifies that \a Type is a POD (plain old
4245 data) type with no constructor or destructor, and for which memcpy()ing
4246 creates a valid independent copy of the object.
4247 \li \c Q_MOVABLE_TYPE specifies that \a Type has a constructor
4248 and/or a destructor but can be moved in memory using \c
4249 memcpy(). Note: despite the name, this has nothing to do with move
4250 constructors or C++ move semantics.
4251 \li \c Q_COMPLEX_TYPE (the default) specifies that \a Type has
4252 constructors and/or a destructor and that it may not be moved
4253 in memory.
4254 \endlist
4255
4256 Example of a "primitive" type:
4257
4258 \snippet code/src_corelib_global_qglobal.cpp 38
4259
4260 An example of a non-POD "primitive" type is QUuid: Even though
4261 QUuid has constructors (and therefore isn't POD), every bit
4262 pattern still represents a valid object, and memcpy() can be used
4263 to create a valid independent copy of a QUuid object.
4264
4265 Example of a movable type:
4266
4267 \snippet code/src_corelib_global_qglobal.cpp 39
4268
4269 Qt will try to detect the class of a type using std::is_trivial or
4270 std::is_trivially_copyable. Use this macro to tune the behavior.
4271 For instance many types would be candidates for Q_MOVABLE_TYPE despite
4272 not being trivially-copyable. For binary compatibility reasons, QList
4273 optimizations are only enabled if there is an explicit
4274 Q_DECLARE_TYPEINFO even for trivially-copyable types.
4275*/
4276
4277/*!
4278 \macro Q_UNUSED(name)
4279 \relates <QtGlobal>
4280
4281 Indicates to the compiler that the parameter with the specified
4282 \a name is not used in the body of a function. This can be used to
4283 suppress compiler warnings while allowing functions to be defined
4284 with meaningful parameter names in their signatures.
4285*/
4286
4287struct QInternal_CallBackTable {
4288 QVector<QList<qInternalCallback> > callbacks;
4289};
4290
4291Q_GLOBAL_STATIC(QInternal_CallBackTable, global_callback_table)
4292
4293bool QInternal::registerCallback(Callback cb, qInternalCallback callback)
4294{
4295 if (unsigned(cb) < unsigned(QInternal::LastCallback)) {
4296 QInternal_CallBackTable *cbt = global_callback_table();
4297 cbt->callbacks.resize(asize: cb + 1);
4298 cbt->callbacks[cb].append(t: callback);
4299 return true;
4300 }
4301 return false;
4302}
4303
4304bool QInternal::unregisterCallback(Callback cb, qInternalCallback callback)
4305{
4306 if (unsigned(cb) < unsigned(QInternal::LastCallback)) {
4307 if (global_callback_table.exists()) {
4308 QInternal_CallBackTable *cbt = global_callback_table();
4309 return (bool) cbt->callbacks[cb].removeAll(t: callback);
4310 }
4311 }
4312 return false;
4313}
4314
4315bool QInternal::activateCallbacks(Callback cb, void **parameters)
4316{
4317 Q_ASSERT_X(cb >= 0, "QInternal::activateCallback()", "Callback id must be a valid id");
4318
4319 if (!global_callback_table.exists())
4320 return false;
4321
4322 QInternal_CallBackTable *cbt = &(*global_callback_table);
4323 if (cbt && cb < cbt->callbacks.size()) {
4324 QList<qInternalCallback> callbacks = cbt->callbacks[cb];
4325 bool ret = false;
4326 for (int i=0; i<callbacks.size(); ++i)
4327 ret |= (callbacks.at(i))(parameters);
4328 return ret;
4329 }
4330 return false;
4331}
4332
4333/*!
4334 \macro Q_BYTE_ORDER
4335 \relates <QtGlobal>
4336
4337 This macro can be used to determine the byte order your system
4338 uses for storing data in memory. i.e., whether your system is
4339 little-endian or big-endian. It is set by Qt to one of the macros
4340 Q_LITTLE_ENDIAN or Q_BIG_ENDIAN. You normally won't need to worry
4341 about endian-ness, but you might, for example if you need to know
4342 which byte of an integer or UTF-16 character is stored in the
4343 lowest address. Endian-ness is important in networking, where
4344 computers with different values for Q_BYTE_ORDER must pass data
4345 back and forth.
4346
4347 Use this macro as in the following examples.
4348
4349 \snippet code/src_corelib_global_qglobal.cpp 40
4350
4351 \sa Q_BIG_ENDIAN, Q_LITTLE_ENDIAN
4352*/
4353
4354/*!
4355 \macro Q_LITTLE_ENDIAN
4356 \relates <QtGlobal>
4357
4358 This macro represents a value you can compare to the macro
4359 Q_BYTE_ORDER to determine the endian-ness of your system. In a
4360 little-endian system, the least significant byte is stored at the
4361 lowest address. The other bytes follow in increasing order of
4362 significance.
4363
4364 \snippet code/src_corelib_global_qglobal.cpp 41
4365
4366 \sa Q_BYTE_ORDER, Q_BIG_ENDIAN
4367*/
4368
4369/*!
4370 \macro Q_BIG_ENDIAN
4371 \relates <QtGlobal>
4372
4373 This macro represents a value you can compare to the macro
4374 Q_BYTE_ORDER to determine the endian-ness of your system. In a
4375 big-endian system, the most significant byte is stored at the
4376 lowest address. The other bytes follow in decreasing order of
4377 significance.
4378
4379 \snippet code/src_corelib_global_qglobal.cpp 42
4380
4381 \sa Q_BYTE_ORDER, Q_LITTLE_ENDIAN
4382*/
4383
4384/*!
4385 \macro QT_NAMESPACE
4386 \internal
4387
4388 If this macro is defined to \c ns all Qt classes are put in a namespace
4389 called \c ns. Also, moc will output code putting metaobjects etc.
4390 into namespace \c ns.
4391
4392 \sa QT_BEGIN_NAMESPACE, QT_END_NAMESPACE,
4393 QT_PREPEND_NAMESPACE, QT_USE_NAMESPACE,
4394 QT_BEGIN_INCLUDE_NAMESPACE, QT_END_INCLUDE_NAMESPACE,
4395 QT_BEGIN_MOC_NAMESPACE, QT_END_MOC_NAMESPACE,
4396*/
4397
4398/*!
4399 \macro QT_PREPEND_NAMESPACE(identifier)
4400 \internal
4401
4402 This macro qualifies \a identifier with the full namespace.
4403 It expands to \c{::QT_NAMESPACE::identifier} if \c QT_NAMESPACE is defined
4404 and only \a identifier otherwise.
4405
4406 \sa QT_NAMESPACE
4407*/
4408
4409/*!
4410 \macro QT_USE_NAMESPACE
4411 \internal
4412
4413 This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined
4414 and nothing otherwise.
4415
4416 \sa QT_NAMESPACE
4417*/
4418
4419/*!
4420 \macro QT_BEGIN_NAMESPACE
4421 \internal
4422
4423 This macro expands to
4424
4425 \snippet code/src_corelib_global_qglobal.cpp begin namespace macro
4426
4427 if \c QT_NAMESPACE is defined and nothing otherwise. If should always
4428 appear in the file-level scope and be followed by \c QT_END_NAMESPACE
4429 at the same logical level with respect to preprocessor conditionals
4430 in the same file.
4431
4432 As a rule of thumb, \c QT_BEGIN_NAMESPACE should appear in all Qt header
4433 and Qt source files after the last \c{#include} line and before the first
4434 declaration.
4435
4436 If that rule can't be followed because, e.g., \c{#include} lines and
4437 declarations are wildly mixed, place \c QT_BEGIN_NAMESPACE before
4438 the first declaration and wrap the \c{#include} lines in
4439 \c QT_BEGIN_INCLUDE_NAMESPACE and \c QT_END_INCLUDE_NAMESPACE.
4440
4441 When using the \c QT_NAMESPACE feature in user code
4442 (e.g., when building plugins statically linked to Qt) where
4443 the user code is not intended to go into the \c QT_NAMESPACE
4444 namespace, all forward declarations of Qt classes need to
4445 be wrapped in \c QT_BEGIN_NAMESPACE and \c QT_END_NAMESPACE.
4446 After that, a \c QT_USE_NAMESPACE should follow.
4447 No further changes should be needed.
4448
4449 \sa QT_NAMESPACE
4450*/
4451
4452/*!
4453 \macro QT_END_NAMESPACE
4454 \internal
4455
4456 This macro expands to
4457
4458 \snippet code/src_corelib_global_qglobal.cpp end namespace macro
4459
4460 if \c QT_NAMESPACE is defined and nothing otherwise. It is used to cancel
4461 the effect of \c QT_BEGIN_NAMESPACE.
4462
4463 If a source file ends with a \c{#include} directive that includes a moc file,
4464 \c QT_END_NAMESPACE should be placed before that \c{#include}.
4465
4466 \sa QT_NAMESPACE
4467*/
4468
4469/*!
4470 \macro QT_BEGIN_INCLUDE_NAMESPACE
4471 \internal
4472
4473 This macro is equivalent to \c QT_END_NAMESPACE.
4474 It only serves as syntactic sugar and is intended
4475 to be used before #include lines within a
4476 \c QT_BEGIN_NAMESPACE ... \c QT_END_NAMESPACE block.
4477
4478 \sa QT_NAMESPACE
4479*/
4480
4481/*!
4482 \macro QT_END_INCLUDE_NAMESPACE
4483 \internal
4484
4485 This macro is equivalent to \c QT_BEGIN_NAMESPACE.
4486 It only serves as syntactic sugar and is intended
4487 to be used after #include lines within a
4488 \c QT_BEGIN_NAMESPACE ... \c QT_END_NAMESPACE block.
4489
4490 \sa QT_NAMESPACE
4491*/
4492
4493/*!
4494 \macro QT_BEGIN_MOC_NAMESPACE
4495 \internal
4496
4497 This macro is output by moc at the beginning of
4498 moc files. It is equivalent to \c QT_USE_NAMESPACE.
4499
4500 \sa QT_NAMESPACE
4501*/
4502
4503/*!
4504 \macro QT_END_MOC_NAMESPACE
4505 \internal
4506
4507 This macro is output by moc at the beginning of
4508 moc files. It expands to nothing.
4509
4510 \sa QT_NAMESPACE
4511*/
4512
4513/*!
4514 \fn bool qFuzzyCompare(double p1, double p2)
4515 \relates <QtGlobal>
4516 \since 4.4
4517 \threadsafe
4518
4519 Compares the floating point value \a p1 and \a p2 and
4520 returns \c true if they are considered equal, otherwise \c false.
4521
4522 Note that comparing values where either \a p1 or \a p2 is 0.0 will not work,
4523 nor does comparing values where one of the values is NaN or infinity.
4524 If one of the values is always 0.0, use qFuzzyIsNull instead. If one of the
4525 values is likely to be 0.0, one solution is to add 1.0 to both values.
4526
4527 \snippet code/src_corelib_global_qglobal.cpp 46
4528
4529 The two numbers are compared in a relative way, where the
4530 exactness is stronger the smaller the numbers are.
4531 */
4532
4533/*!
4534 \fn bool qFuzzyCompare(float p1, float p2)
4535 \relates <QtGlobal>
4536 \since 4.4
4537 \threadsafe
4538
4539 Compares the floating point value \a p1 and \a p2 and
4540 returns \c true if they are considered equal, otherwise \c false.
4541
4542 The two numbers are compared in a relative way, where the
4543 exactness is stronger the smaller the numbers are.
4544 */
4545
4546/*!
4547 \fn bool qFuzzyIsNull(double d)
4548 \relates <QtGlobal>
4549 \since 4.4
4550 \threadsafe
4551
4552 Returns true if the absolute value of \a d is within 0.000000000001 of 0.0.
4553*/
4554
4555/*!
4556 \fn bool qFuzzyIsNull(float f)
4557 \relates <QtGlobal>
4558 \since 4.4
4559 \threadsafe
4560
4561 Returns true if the absolute value of \a f is within 0.00001f of 0.0.
4562*/
4563
4564/*!
4565 \macro QT_REQUIRE_VERSION(int argc, char **argv, const char *version)
4566 \relates <QtGlobal>
4567
4568 This macro can be used to ensure that the application is run
4569 against a recent enough version of Qt. This is especially useful
4570 if your application depends on a specific bug fix introduced in a
4571 bug-fix release (e.g., 4.0.2).
4572
4573 The \a argc and \a argv parameters are the \c main() function's
4574 \c argc and \c argv parameters. The \a version parameter is a
4575 string literal that specifies which version of Qt the application
4576 requires (e.g., "4.0.2").
4577
4578 Example:
4579
4580 \snippet code/src_gui_dialogs_qmessagebox.cpp 4
4581*/
4582
4583/*!
4584 \macro Q_DECL_EXPORT
4585 \relates <QtGlobal>
4586
4587 This macro marks a symbol for shared library export (see
4588 \l{sharedlibrary.html}{Creating Shared Libraries}).
4589
4590 \sa Q_DECL_IMPORT
4591*/
4592
4593/*!
4594 \macro Q_DECL_IMPORT
4595 \relates <QtGlobal>
4596
4597 This macro declares a symbol to be an import from a shared library (see
4598 \l{sharedlibrary.html}{Creating Shared Libraries}).
4599
4600 \sa Q_DECL_EXPORT
4601*/
4602
4603/*!
4604 \macro Q_DECL_CONSTEXPR
4605 \relates <QtGlobal>
4606
4607 This macro can be used to declare variable that should be constructed at compile-time,
4608 or an inline function that can be computed at compile-time.
4609
4610 It expands to "constexpr" if your compiler supports that C++11 keyword, or to nothing
4611 otherwise.
4612
4613 \sa Q_DECL_RELAXED_CONSTEXPR
4614*/
4615
4616/*!
4617 \macro Q_DECL_RELAXED_CONSTEXPR
4618 \relates <QtGlobal>
4619
4620 This macro can be used to declare an inline function that can be computed
4621 at compile-time according to the relaxed rules from C++14.
4622
4623 It expands to "constexpr" if your compiler supports C++14 relaxed constant
4624 expressions, or to nothing otherwise.
4625
4626 \sa Q_DECL_CONSTEXPR
4627*/
4628
4629/*!
4630 \macro qDebug(const char *message, ...)
4631 \relates <QtGlobal>
4632 \threadsafe
4633
4634 Calls the message handler with the debug message \a message. If no
4635 message handler has been installed, the message is printed to
4636 stderr. Under Windows the message is sent to the console, if it is a
4637 console application; otherwise, it is sent to the debugger. On QNX, the
4638 message is sent to slogger2. This function does nothing if \c QT_NO_DEBUG_OUTPUT
4639 was defined during compilation.
4640
4641 If you pass the function a format string and a list of arguments,
4642 it works in similar way to the C printf() function. The format
4643 should be a Latin-1 string.
4644
4645 Example:
4646
4647 \snippet code/src_corelib_global_qglobal.cpp 24
4648
4649 If you include \c <QtDebug>, a more convenient syntax is also
4650 available:
4651
4652 \snippet code/src_corelib_global_qglobal.cpp 25
4653
4654 With this syntax, the function returns a QDebug object that is
4655 configured to use the QtDebugMsg message type. It automatically
4656 puts a single space between each item, and outputs a newline at
4657 the end. It supports many C++ and Qt types.
4658
4659 To suppress the output at run-time, install your own message handler
4660 with qInstallMessageHandler().
4661
4662 \sa qInfo(), qWarning(), qCritical(), qFatal(), qInstallMessageHandler(),
4663 {Debugging Techniques}
4664*/
4665
4666/*!
4667 \macro qInfo(const char *message, ...)
4668 \relates <QtGlobal>
4669 \threadsafe
4670 \since 5.5
4671
4672 Calls the message handler with the informational message \a message. If no
4673 message handler has been installed, the message is printed to
4674 stderr. Under Windows, the message is sent to the console, if it is a
4675 console application; otherwise, it is sent to the debugger. On QNX the
4676 message is sent to slogger2. This function does nothing if \c QT_NO_INFO_OUTPUT
4677 was defined during compilation.
4678
4679 If you pass the function a format string and a list of arguments,
4680 it works in similar way to the C printf() function. The format
4681 should be a Latin-1 string.
4682
4683 Example:
4684
4685 \snippet code/src_corelib_global_qglobal.cpp qInfo_printf
4686
4687 If you include \c <QtDebug>, a more convenient syntax is also
4688 available:
4689
4690 \snippet code/src_corelib_global_qglobal.cpp qInfo_stream
4691
4692 With this syntax, the function returns a QDebug object that is
4693 configured to use the QtInfoMsg message type. It automatically
4694 puts a single space between each item, and outputs a newline at
4695 the end. It supports many C++ and Qt types.
4696
4697 To suppress the output at run-time, install your own message handler
4698 with qInstallMessageHandler().
4699
4700 \sa qDebug(), qWarning(), qCritical(), qFatal(), qInstallMessageHandler(),
4701 {Debugging Techniques}
4702*/
4703
4704/*!
4705 \macro qWarning(const char *message, ...)
4706 \relates <QtGlobal>
4707 \threadsafe
4708
4709 Calls the message handler with the warning message \a message. If no
4710 message handler has been installed, the message is printed to
4711 stderr. Under Windows, the message is sent to the debugger.
4712 On QNX the message is sent to slogger2. This
4713 function does nothing if \c QT_NO_WARNING_OUTPUT was defined
4714 during compilation; it exits if at the nth warning corresponding to the
4715 counter in environment variable \c QT_FATAL_WARNINGS. That is, if the
4716 environment variable contains the value 1, it will exit on the 1st message;
4717 if it contains the value 10, it will exit on the 10th message. Any
4718 non-numeric value is equivalent to 1.
4719
4720 This function takes a format string and a list of arguments,
4721 similar to the C printf() function. The format should be a Latin-1
4722 string.
4723
4724 Example:
4725 \snippet code/src_corelib_global_qglobal.cpp 26
4726
4727 If you include <QtDebug>, a more convenient syntax is
4728 also available:
4729
4730 \snippet code/src_corelib_global_qglobal.cpp 27
4731
4732 This syntax inserts a space between each item, and
4733 appends a newline at the end.
4734
4735 To suppress the output at runtime, install your own message handler
4736 with qInstallMessageHandler().
4737
4738 \sa qDebug(), qInfo(), qCritical(), qFatal(), qInstallMessageHandler(),
4739 {Debugging Techniques}
4740*/
4741
4742/*!
4743 \macro qCritical(const char *message, ...)
4744 \relates <QtGlobal>
4745 \threadsafe
4746
4747 Calls the message handler with the critical message \a message. If no
4748 message handler has been installed, the message is printed to
4749 stderr. Under Windows, the message is sent to the debugger.
4750 On QNX the message is sent to slogger2.
4751
4752 It exits if the environment variable QT_FATAL_CRITICALS is not empty.
4753
4754 This function takes a format string and a list of arguments,
4755 similar to the C printf() function. The format should be a Latin-1
4756 string.
4757
4758 Example:
4759 \snippet code/src_corelib_global_qglobal.cpp 28
4760
4761 If you include <QtDebug>, a more convenient syntax is
4762 also available:
4763
4764 \snippet code/src_corelib_global_qglobal.cpp 29
4765
4766 A space is inserted between the items, and a newline is
4767 appended at the end.
4768
4769 To suppress the output at runtime, install your own message handler
4770 with qInstallMessageHandler().
4771
4772 \sa qDebug(), qInfo(), qWarning(), qFatal(), qInstallMessageHandler(),
4773 {Debugging Techniques}
4774*/
4775
4776/*!
4777 \macro qFatal(const char *message, ...)
4778 \relates <QtGlobal>
4779
4780 Calls the message handler with the fatal message \a message. If no
4781 message handler has been installed, the message is printed to
4782 stderr. Under Windows, the message is sent to the debugger.
4783 On QNX the message is sent to slogger2.
4784
4785 If you are using the \b{default message handler} this function will
4786 abort to create a core dump. On Windows, for debug builds,
4787 this function will report a _CRT_ERROR enabling you to connect a debugger
4788 to the application.
4789
4790 This function takes a format string and a list of arguments,
4791 similar to the C printf() function.
4792
4793 Example:
4794 \snippet code/src_corelib_global_qglobal.cpp 30
4795
4796 To suppress the output at runtime, install your own message handler
4797 with qInstallMessageHandler().
4798
4799 \sa qDebug(), qInfo(), qWarning(), qCritical(), qInstallMessageHandler(),
4800 {Debugging Techniques}
4801*/
4802
4803/*!
4804 \macro qMove(x)
4805 \relates <QtGlobal>
4806 \obsolete
4807
4808 Use \c std::move instead.
4809
4810 It expands to "std::move".
4811
4812 qMove takes an rvalue reference to its parameter \a x, and converts it to an xvalue.
4813*/
4814
4815/*!
4816 \macro Q_DECL_NOTHROW
4817 \relates <QtGlobal>
4818 \since 5.0
4819
4820 This macro marks a function as never throwing, under no
4821 circumstances. If the function does nevertheless throw, the
4822 behaviour is undefined.
4823
4824 The macro expands to either "throw()", if that has some benefit on
4825 the compiler, or to C++11 noexcept, if available, or to nothing
4826 otherwise.
4827
4828 If you need C++11 noexcept semantics, don't use this macro, use
4829 Q_DECL_NOEXCEPT/Q_DECL_NOEXCEPT_EXPR instead.
4830
4831 \sa Q_DECL_NOEXCEPT, Q_DECL_NOEXCEPT_EXPR()
4832*/
4833
4834/*!
4835 \macro QT_TERMINATE_ON_EXCEPTION(expr)
4836 \relates <QtGlobal>
4837 \internal
4838
4839 In general, use of the Q_DECL_NOEXCEPT macro is preferred over
4840 Q_DECL_NOTHROW, because it exhibits well-defined behavior and
4841 supports the more powerful Q_DECL_NOEXCEPT_EXPR variant. However,
4842 use of Q_DECL_NOTHROW has the advantage that Windows builds
4843 benefit on a wide range or compiler versions that do not yet
4844 support the C++11 noexcept feature.
4845
4846 It may therefore be beneficial to use Q_DECL_NOTHROW and emulate
4847 the C++11 behavior manually with an embedded try/catch.
4848
4849 Qt provides the QT_TERMINATE_ON_EXCEPTION(expr) macro for this
4850 purpose. It either expands to \c expr (if Qt is compiled without
4851 exception support or the compiler supports C++11 noexcept
4852 semantics) or to
4853 \snippet code/src_corelib_global_qglobal.cpp qterminate
4854 otherwise.
4855
4856 Since this macro expands to just \c expr if the compiler supports
4857 C++11 noexcept, expecting the compiler to take over responsibility
4858 of calling std::terminate() in that case, it should not be used
4859 outside Q_DECL_NOTHROW functions.
4860
4861 \sa Q_DECL_NOEXCEPT, Q_DECL_NOTHROW, qTerminate()
4862*/
4863
4864/*!
4865 \macro Q_DECL_NOEXCEPT
4866 \relates <QtGlobal>
4867 \since 5.0
4868
4869 This macro marks a function as never throwing. If the function
4870 does nevertheless throw, the behaviour is defined:
4871 std::terminate() is called.
4872
4873 The macro expands to C++11 noexcept, if available, or to nothing
4874 otherwise.
4875
4876 If you need the operator version of C++11 noexcept, use
4877 Q_DECL_NOEXCEPT_EXPR(x).
4878
4879 If you don't need C++11 noexcept semantics, e.g. because your
4880 function can't possibly throw, don't use this macro, use
4881 Q_DECL_NOTHROW instead.
4882
4883 \sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT_EXPR()
4884*/
4885
4886/*!
4887 \macro Q_DECL_NOEXCEPT_EXPR(x)
4888 \relates <QtGlobal>
4889 \since 5.0
4890
4891 This macro marks a function as non-throwing if \a x is \c true. If
4892 the function does nevertheless throw, the behaviour is defined:
4893 std::terminate() is called.
4894
4895 The macro expands to C++11 noexcept(x), if available, or to
4896 nothing otherwise.
4897
4898 If you need the always-true version of C++11 noexcept, use
4899 Q_DECL_NOEXCEPT.
4900
4901 If you don't need C++11 noexcept semantics, e.g. because your
4902 function can't possibly throw, don't use this macro, use
4903 Q_DECL_NOTHROW instead.
4904
4905 \sa Q_DECL_NOTHROW, Q_DECL_NOEXCEPT
4906*/
4907
4908/*!
4909 \macro Q_DECL_OVERRIDE
4910 \since 5.0
4911 \obsolete
4912 \relates <QtGlobal>
4913
4914 This macro can be used to declare an overriding virtual
4915 function. Use of this markup will allow the compiler to generate
4916 an error if the overriding virtual function does not in fact
4917 override anything.
4918
4919 It expands to "override".
4920
4921 The macro goes at the end of the function, usually after the
4922 \c{const}, if any:
4923 \snippet code/src_corelib_global_qglobal.cpp qdecloverride
4924
4925 \sa Q_DECL_FINAL
4926*/
4927
4928/*!
4929 \macro Q_DECL_FINAL
4930 \since 5.0
4931 \obsolete
4932 \relates <QtGlobal>
4933
4934 This macro can be used to declare an overriding virtual or a class
4935 as "final", with Java semantics. Further-derived classes can then
4936 no longer override this virtual function, or inherit from this
4937 class, respectively.
4938
4939 It expands to "final".
4940
4941 The macro goes at the end of the function, usually after the
4942 \c{const}, if any:
4943 \snippet code/src_corelib_global_qglobal.cpp qdeclfinal-1
4944
4945 For classes, it goes in front of the \c{:} in the class
4946 definition, if any:
4947 \snippet code/src_corelib_global_qglobal.cpp qdeclfinal-2
4948
4949 \sa Q_DECL_OVERRIDE
4950*/
4951
4952/*!
4953 \macro Q_FORWARD_DECLARE_OBJC_CLASS(classname)
4954 \since 5.2
4955 \relates <QtGlobal>
4956
4957 Forward-declares an Objective-C \a classname in a manner such that it can be
4958 compiled as either Objective-C or C++.
4959
4960 This is primarily intended for use in header files that may be included by
4961 both Objective-C and C++ source files.
4962*/
4963
4964/*!
4965 \macro Q_FORWARD_DECLARE_CF_TYPE(type)
4966 \since 5.2
4967 \relates <QtGlobal>
4968
4969 Forward-declares a Core Foundation \a type. This includes the actual
4970 type and the ref type. For example, Q_FORWARD_DECLARE_CF_TYPE(CFString)
4971 declares __CFString and CFStringRef.
4972*/
4973
4974/*!
4975 \macro Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type)
4976 \since 5.2
4977 \relates <QtGlobal>
4978
4979 Forward-declares a mutable Core Foundation \a type. This includes the actual
4980 type and the ref type. For example, Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(CFMutableString)
4981 declares __CFMutableString and CFMutableStringRef.
4982*/
4983
4984QT_END_NAMESPACE
4985

source code of qtbase/src/corelib/global/qglobal.cpp