Is there Q_OBSOLETE or Q_DEPRECATED in C++ with Qt 4.7?
Or is there a similar C++ macro or keyword?
Is there Q_OBSOLETE or Q_DEPRECATED in C++ with Qt 4.7?
Or is there a similar C++ macro or keyword?
Yes, the Qt is defined QT_DEPRECATED
and QT_DEPRECATED_X
macros for this purpose:
QT_DEPRECATED void myOldFunc();
QT_DEPRECATED_X("use myNewFunc instead") void myOldFunc2();
difference is just the text message.
Also the C++14 presents [[deprecated("text")]]
attribute as standard. It seems that this attribute is used under the hood if you use C++ 14+.
QT_DEPRECATED
and QT_DEPRECATED_X("message")
(notice: QT, not Q). –
Pereyra qglobal.h
for differences between that two macros. Some other macros rely on the QT_DEPRECATED
. Also, yeah! You right. I had a misspelling about the Q_DEPRECATED
. –
Facture If you use Q_DECL_DEPRECATED you should get the outcome you are looking for e.g.:
Q_DECL_DEPRECATED void foo();
Just use the
#warning
directive
although is not C++ standard is quite unlikely you will encounter a compiler that does not support it (see this SO question).
You might want to do something similiar yourself:
#ifdef Q_TREAT_OBSOLETE_AS_ERRORS
#define Q_OBSOLETE(X) \
BOOST_STATIC_ASSERT(false); \
X
#else
#define Q_OBSOLETE(X) X
#endif
This construction simply substitutes some deprecated code / part of code if there is no Q_TREAT_OBSOLETE_AS_ERRORS
defined and generates compilation-time error otherwise.
Note that BOOST_STATIC_ASSERT
has no scope limitations, so does the Q_OBSOLETE
macro.
Probably this is not the best way to solve your problem and actually I'm not sure this is useful.
You might just mark the code as @obsolete
or simply point it out in the comments.
Yes, the Qt is defined QT_DEPRECATED
and QT_DEPRECATED_X
macros for this purpose:
QT_DEPRECATED void myOldFunc();
QT_DEPRECATED_X("use myNewFunc instead") void myOldFunc2();
difference is just the text message.
Also the C++14 presents [[deprecated("text")]]
attribute as standard. It seems that this attribute is used under the hood if you use C++ 14+.
QT_DEPRECATED
and QT_DEPRECATED_X("message")
(notice: QT, not Q). –
Pereyra qglobal.h
for differences between that two macros. Some other macros rely on the QT_DEPRECATED
. Also, yeah! You right. I had a misspelling about the Q_DEPRECATED
. –
Facture By "deprecated constructs", you really mean "deprecated member functions". You're asking for a compile-time warning to draw your attention to the call site of any deprecated function.
This isn't possible in any reasonable way in standard C++, and I don't see any attributes in G++ that would support this either. Qt can't really add a feature like that if the compiler doesn't have some support for it already.
However, Microsoft Visual C++ supports an __declspec(deprecated)
extension, and I would imagine it's possible to write a compiler plugin for G++ 4.5 that adds a similar feature.
__attribute__((deprecated))
in G++. –
Tails [[deprecated]]
keyword that you can add to some functions en.cppreference.com/w/cpp/language/attributes –
Vallievalliere © 2022 - 2024 — McMap. All rights reserved.