Results 1 to 4 of 4

Thread: Getting type of object

  1. #1
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Getting type of object

    Hi,

    Is there anyway to determine the type of an object? I have various QWidgets ( QPushButton, QCheckBox ) that are connected to a QSignalMapper and go to the same slot. In this slot, I'd like to know if it was a QCheckBox that caused the signal to be raised or QPushButton, is this possible?

    Regards,
    Steve

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Getting type of object

    For all QObjects you can use QMetaObject::className(), but if you have to distinguish between check boxes and push buttons, then most likely you need two slots.

  3. #3
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: Getting type of object

    Hello.

    I haven't used QSignalMapper, and quite possibly that provides a better option somewhere.

    I'd check QMetaObject, especially with regards to the className() method.

    Good luck.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Getting type of object

    Using qobject_cast<>() is probably the most straightforward thing to do.

Similar Threads

  1. Installation on Fedora Core 4
    By jcr in forum Installation and Deployment
    Replies: 3
    Last Post: 29th January 2009, 01:34
  2. Make error with Qt Jambi 4.3.2_01
    By pamalite in forum Installation and Deployment
    Replies: 0
    Last Post: 22nd November 2007, 12:05
  3. Replies: 6
    Last Post: 21st September 2007, 13:51
  4. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38
  5. Replies: 3
    Last Post: 15th April 2007, 19:16

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.