Results 1 to 3 of 3

Thread: Determine Class Type of QObject Parent

  1. #1
    Join Date
    Feb 2010
    Posts
    20
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default 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.

  3. #3
    Join Date
    Feb 2010
    Posts
    20
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Determine Class Type of QObject Parent

    qobject_cast<> worked exactly as I needed.

    Thanks.

Similar Threads

  1. Replies: 5
    Last Post: 28th March 2010, 16:26
  2. [solved] Which object type is QObject::sender()?
    By ricardo in forum Qt Programming
    Replies: 6
    Last Post: 8th May 2009, 21:03
  3. QObject::connect: Cannot queue arguments of type 'QString&'
    By Dumbledore in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2007, 22:15
  4. Replies: 6
    Last Post: 21st September 2007, 13:51
  5. QWorkSpace parent type optional?
    By brcain in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2006, 00:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.