New Feature: Compiler Errors

Since dynamic_cast doesn't reliably work between library boundaries, Qt introduced qobject_cast to safely cast between QObject subclasses. There's just one requirement - the class you want to cast to must contain a Q_OBJECT macro. Without the macro, qobject_cast would fail at runtime, which makes it tedious to debug.

Qt 4.3 now includes a compile check that makes sure the Q_OBJECT macro is present when casting objects. If you get a compile error in a function called qYouForgotTheQ_OBJECT_Macro, just add the Q_OBJECT macro to the class and lean back knowing that you just saved yourself some debugging time.


Blog Topics:

Comments