I have some interesting need in showing a compilation error if the declaration of the type I was given doesn't contain the Q_OBJECT
macro. I found one bad way to do it. Actually it repeats the idea of Qt developers to do the same trick:
template<typename T>
void checkForQObjectMacro()
{
reinterpret_cast<T *>(0)->qt_check_for_QOBJECT_macro(*reinterpret_cast<T *>(0));
}
This works well but it gives indeed strange error message. I want to show a readable message. One way to do this is using static_assert
construction. But I have no idea how to implement statically verified condition of Q_OBJECT
macro presence. Maybe someone can propose a beautiful hack? Also any idea is greatly appreciated.