diff --git a/src/corelib/global/qtversionchecks.h b/src/corelib/global/qtversionchecks.h index 7b5d99af869..14df2780d85 100644 --- a/src/corelib/global/qtversionchecks.h +++ b/src/corelib/global/qtversionchecks.h @@ -72,4 +72,43 @@ # define QT6_CALL_NEW_OVERLOAD_TAIL QT6_ONLY(, QT6_CALL_NEW_OVERLOAD) #endif +/* + Macro to tag Tech Preview APIs. + It expands to nothing, because we want to use it in places where + nothing is generally allowed (not even an attribute); for instance: + to tag other macros, Q_PROPERTY declarations, and so on. + + Still: use it as if it were an C++ attribute. + + To mark a class as TP: + class QT_TECH_PREVIEW_API Q_CORE_EXPORT QClass { ... }; + + To mark a function: + QT_TECH_PREVIEW_API void qFunction(); + + To mark an enumeration or enumerator: + enum class QT_TECH_PREVIEW_API QEnum { + Enum1, + Enum2 QT_TECH_PREVIEW_API, + }; + + To mark parts of a class: + class QClass : public QObject + { + Q_OBJECT + + QT_TECH_PREVIEW_API + Q_PROPERTY(int countNG ...) // this is TP + + Q_PROPERTY(int count ...) // this is stable API + + public: + QT_TECH_PREVIEW_API + void f(); // TP + + void g(); // stable + }; +*/ +#define QT_TECH_PREVIEW_API + #endif /* QTVERSIONCHECKS_H */ diff --git a/tests/auto/tools/moc/tech-preview.h b/tests/auto/tools/moc/tech-preview.h new file mode 100644 index 00000000000..8f285048e4e --- /dev/null +++ b/tests/auto/tools/moc/tech-preview.h @@ -0,0 +1,43 @@ +// Copyright (C) 2024 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef TECH_PREVIEW_H +#define TECH_PREVIEW_H + +#include + +class QT_TECH_PREVIEW_API MyTechPreviewObject : public QObject +{ + QT_TECH_PREVIEW_API + Q_OBJECT + + QT_TECH_PREVIEW_API + Q_PROPERTY(int status MEMBER m_status) + + int m_status = 0; + +public: + void myMethod() {} + QT_TECH_PREVIEW_API void myTPMethod() {} + + Q_INVOKABLE QT_TECH_PREVIEW_API void myTPInvokable1() {} + QT_TECH_PREVIEW_API Q_INVOKABLE void myTPInvokable2() {} + + enum class QT_TECH_PREVIEW_API MyTechPreviewEnum + { + A, B, C, + TP QT_TECH_PREVIEW_API, + X, Y, Z + }; + +signals: + void mySignal(); + QT_TECH_PREVIEW_API void myTPSignal(); + +public Q_SLOTS: + void mySlot() {} + QT_TECH_PREVIEW_API void myTPSlot() {} +}; + + +#endif // TECH_PREVIEW_H diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 3fe170a9a70..a671d92dade 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -62,6 +62,8 @@ #include "qmlmacro.h" +#include "tech-preview.h" + using namespace Qt::StringLiterals; #ifdef Q_MOC_RUN