Determine Class Type of QObject Parent
I have a Qt GUI project where I am walking back up the QObject tree looking for a parent window class of QMainWindow. I can find that object using the name of the object. However, this is not very general.
My problem is, in reviewing the documentation, I cannot determine how to retrieve the class type of the object that I'm looking at. And in looking in the debug window, I can see the class name. I just cannot figure out how to retrieve it.
Suggestions?
Re: Determine Class Type of QObject Parent
You can use the C++ RTTI (Run Time Type Identification) mechanism if your compiler and C++ library supports it; some don't. See 'typeid' for starters. You can also use dynamic_cast<>, or the Qt-provided qobject_cast<>, to compare the type of your pointers with known types to see if they're the same.
Re: Determine Class Type of QObject Parent
qobject_cast<> worked exactly as I needed.
Thanks.