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