| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 2 | |
HI. I want to determine at runtime the class of an object. My first idea was to do it with parent () and typeid, but parent() return QObject*. assert( typeid( this->parent() ) == typeid( QWidget ) ) ; Is there an easy QT-way to know, of which classtype my Object is. If not, I must derive my own classes from QWidget an give them a methode widgetClassID(). Thanks in advance. Rainer
Hello, On Wed, Mar 07, 2001 at 11:05:03AM +0100, Rainer Grimm wrote: > Is there an easy QT-way to know, of which classtype my Object is. > If not, I must derive my own classes from QWidget an give them a methode > widgetClassID(). Yes, you can use QObject::className() for this. Greetings, Wilco
Am Mittwoch, 7. März 2001 11:05 schrieb Rainer Grimm: > HI. > > > I want to determine at runtime the class of an object. > My first idea was to do it with parent () and typeid, but parent() > return QObject*. > > assert( typeid( this->parent() ) == typeid( QWidget ) ) ; > > Is there an easy QT-way to know, of which classtype my Object is. > If not, I must derive my own classes from QWidget an give them a methode > widgetClassID(). QObject::className() tells you the actual class name of the widget (as QWidget inherits QObject) and QObject::inherits(const char *classname) returns true if the object is or inherits the class given by name. Just make sure you have a Q_OBJECT macro in the class declaration as this works via the meta class. -Malte
Rainer Grimm wrote: > > HI. > > I want to determine at runtime the class of an object. > My first idea was to do it with parent () and typeid, but parent() > return QObject*. > > assert( typeid( this->parent() ) == typeid( QWidget ) ) ; > > Is there an easy QT-way to know, of which classtype my Object is. > If not, I must derive my own classes from QWidget an give them a methode > widgetClassID(). > > Thanks in advance. > > Rainer > > -- > List archive and information: http://qt-interest.trolltech.com All right. Thanks everybody for your help. Rainer
> HI. > > > I want to determine at runtime the class of an object. > My first idea was to do it with parent () and typeid, but parent() > return QObject*. > > assert( typeid( this->parent() ) == typeid( QWidget ) ) ; > > Is there an easy QT-way to know, of which classtype my Object is. > If not, I must derive my own classes from QWidget an give > them a methode > widgetClassID(). You might want to look into: QObject::isA QObject::inherits and the stuff to be found in the QMetaObject Regards.. -- [ signature omitted ]
> > I want to determine at runtime the class of an object. > > My first idea was to do it with parent () and typeid, but parent() > > return QObject*. > > > > assert( typeid( this->parent() ) == typeid( QWidget ) ) ; > > > > Is there an easy QT-way to know, of which classtype my Object is. > > If not, I must derive my own classes from QWidget an give > > them a methode > > widgetClassID(). > > You might want to look into: > QObject::isA > QObject::inherits > and the stuff to be found in the QMetaObject There was also recently a disscution on this list of the use of dynamic_cast (a C++ and therefore maybe a Qt way). Instead of bringing the debate up again you might want to check some archives. -- [ signature omitted ]
<<< text/html: EXCLUDED >>>
Hi, every QObject-derived class has a method called className() that returns exactly the class name (like "QWidget"). It also works with derived classes as the code is implemented in the moc-generated file. cheers, teddy > HI. > > > I want to determine at runtime the class of an object. > My first idea was to do it with parent () and typeid, but parent() > return QObject*. > > assert( typeid( this->parent() ) == typeid( QWidget ) ) ; > > Is there an easy QT-way to know, of which classtype my Object is. > If not, I must derive my own classes from QWidget an give them a methode > widgetClassID(). > > Thanks in advance. > > Rainer > > -- > List archive and information: http://qt-interest.trolltech.com