How to mark something in Qt as obsolete(deprecated)?

Is there Q_OBSOLETE or Q_DEPRECATED in C++ with Qt 4.7?

Or is there a similar C++ macro or keyword?


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.

If you use Q_DECL_DEPRECATED you should get the outcome you are looking for e.g.:


  1. Pull the real function out of public scope.
  2. Create another function with the same name in public scope.
  3. Insert your warning/fail code in that function.
  4. Call the original with the new.

Just use the



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:

#define Q_OBSOLETE(X) \
        BOOST_STATIC_ASSERT(false); \

#define Q_OBSOLETE(X) X

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.

Need Your Help

How do you use pip, virtualenv and Fabric to handle deployment?

python deployment virtualenv fabric pip

What are your settings, your tricks, and above all, your workflow?

Berkeley Socket facade for WinRT Networking plausibility?

sockets windows-8 microsoft-metro windows-runtime zeromq

This is a copy of a post I've sent to the ZeroMQ mailing list. However, the question is raises it not specific to ZeroMQ, but more generally regarding the need for a 'mapping' layer over the networ...