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