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

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