Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtversionchecks.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QTVERSIONCHECKS_H
6#define QTVERSIONCHECKS_H
7
8#if 0
9#pragma qt_class(QtVersionChecks)
10#pragma qt_sync_stop_processing
11#endif
12
13#include <QtCore/qtconfiginclude.h>
14
15/*
16 QT_VERSION is (major << 16) | (minor << 8) | patch.
17*/
18#define QT_VERSION QT_VERSION_CHECK(QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH)
19/*
20 can be used like #if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0))
21*/
22#define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
23
24/*
25 Helper macros to make some simple code active in Qt 6 or Qt 7 only,
26 like:
27 struct QT6_ONLY(Q_CORE_EXPORT) QTrivialClass
28 {
29 void QT7_ONLY(Q_CORE_EXPORT) void operate();
30 }
31*/
32#if QT_VERSION_MAJOR == 7 || defined(QT_BOOTSTRAPPED)
33# define QT7_ONLY(...) __VA_ARGS__
34# define QT6_ONLY(...)
35#elif QT_VERSION_MAJOR == 6
36# define QT7_ONLY(...)
37# define QT6_ONLY(...) __VA_ARGS__
38#else
39# error Qt major version not 6 or 7
40#endif
41
42/* Macro and tag type to help overload resolution on functions
43 that are, e.g., QT_REMOVED_SINCE'ed. Example use:
44
45 #if QT_CORE_REMOVED_SINCE(6, 4)
46 int size() const;
47 #endif
48 qsizetype size(QT6_DECL_NEW_OVERLOAD) const;
49
50 in the normal cpp file:
51
52 qsizetype size(QT6_IMPL_NEW_OVERLOAD) const {
53 ~~~
54 }
55
56 in removed_api.cpp:
57
58 int size() const { return int(size(QT6_CALL_NEW_OVERLOAD)); }
59*/
60#ifdef Q_QDOC
61# define QT6_DECL_NEW_OVERLOAD
62# define QT6_DECL_NEW_OVERLOAD_TAIL
63# define QT6_IMPL_NEW_OVERLOAD
64# define QT6_IMPL_NEW_OVERLOAD_TAIL
65# define QT6_CALL_NEW_OVERLOAD
66# define QT6_CALL_NEW_OVERLOAD_TAIL
67#else
68# define QT6_DECL_NEW_OVERLOAD QT6_ONLY(Qt::Disambiguated_t = Qt::Disambiguated)
69# define QT6_DECL_NEW_OVERLOAD_TAIL QT6_ONLY(, QT6_DECL_NEW_OVERLOAD)
70# define QT6_IMPL_NEW_OVERLOAD QT6_ONLY(Qt::Disambiguated_t)
71# define QT6_IMPL_NEW_OVERLOAD_TAIL QT6_ONLY(, QT6_IMPL_NEW_OVERLOAD)
72# define QT6_CALL_NEW_OVERLOAD QT6_ONLY(Qt::Disambiguated)
73# define QT6_CALL_NEW_OVERLOAD_TAIL QT6_ONLY(, QT6_CALL_NEW_OVERLOAD)
74#endif
75
76/*
77 Macro to tag Tech Preview APIs.
78 It expands to nothing, because we want to use it in places where
79 nothing is generally allowed (not even an attribute); for instance:
80 to tag other macros, Q_PROPERTY declarations, and so on.
81
82 Still: use it as if it were an C++ attribute.
83
84 To mark a class as TP:
85 class QT_TECH_PREVIEW_API Q_CORE_EXPORT QClass { ... };
86
87 To mark a function:
88 QT_TECH_PREVIEW_API void qFunction();
89
90 To mark an enumeration or enumerator:
91 enum class QT_TECH_PREVIEW_API QEnum {
92 Enum1,
93 Enum2 QT_TECH_PREVIEW_API,
94 };
95
96 To mark parts of a class:
97 class QClass : public QObject
98 {
99 // Q_OBJECT omitted d/t QTBUG-123229
100
101 QT_TECH_PREVIEW_API
102 Q_PROPERTY(int countNG ...) // this is TP
103
104 Q_PROPERTY(int count ...) // this is stable API
105
106 public:
107 QT_TECH_PREVIEW_API
108 void f(); // TP
109
110 void g(); // stable
111 };
112*/
113#define QT_TECH_PREVIEW_API
114
115#endif /* QTVERSIONCHECKS_H */
#define QT_VERSION_CHECK(major, minor, patch)
#define QT6_IMPL_NEW_OVERLOAD
#define QT6_DECL_NEW_OVERLOAD
#define QT6_CALL_NEW_OVERLOAD