Back to Blog home

New Feature: Compiler Errors

Published on Monday February 26, 2007 by Harald Fernengel in Qt Qtopia | Comments

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.

Subscribe to Our Blog

Stay up to date with the latest marketing, sales and service tips and news.

The blog comment system has been migrated to a new platform. If you face any issues, please let us know via