PDA

View Full Version : Determine Class Type of QObject Parent



photo_tom
12th May 2010, 16:45
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?

SixDegrees
12th May 2010, 16:52
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.

photo_tom
12th May 2010, 17:42
qobject_cast<> worked exactly as I needed.

Thanks.