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