Results 1 to 2 of 2

Thread: Getting Type of an variable

  1. #1
    Join Date
    Jul 2007
    Posts
    104
    Thanks
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Getting Type of an variable

    How can I find which type of my variable?Is there a pratical way?EX.QComboBox *combo;
    type(combo)==QComboBox mean;

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Getting Type of an variable

    If you want type information about non-Qt objects you will have to use some reflection mechanism(there are a few libraries available).

    For Qt objects, you have QObject::inherits and QMetaObject::className and QMetaObject::superClass.

    Or you can use dynamic_cast:
    Qt Code:
    1. if(dynamic_cast<QComboBox*>(combo) != null)
    2. // do someyhing
    To copy to clipboard, switch view to plain text mode 
    Note in this case you need a pointer to QComboBox.

    Regards

  3. The following user says thank you to marcel for this useful post:

    hgedek (9th September 2007)

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. Replies: 6
    Last Post: 21st September 2007, 13:51
  3. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38
  4. How to dinamically change the type of a QCheckListItem
    By kalos80 in forum Qt Programming
    Replies: 4
    Last Post: 12th March 2007, 15:25
  5. custom plugin designer property with out a variable?
    By high_flyer in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2006, 19:11

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.