Hey that clue was good I looked in the qobjectdefs.h & then I stumbled upon staticMetaObject() atleast it is there in Qt 3.3.6
So I re wrote the qobject_cast And Guess what ?? you can use qobject_cast< QClassName *>( object );
And for qt_cast : I have no clue
( atleast for now )
So here is the new Code qobject_cast
#include <qmetaobject.h>
template < typename T >
inline T qobject_cast
( QObject *object
){ T dummy;
if( object->inherits( dummy->staticMetaObject()->className()) ){
return static_cast< T >( object );
}
return 0;
}
#include <qmetaobject.h>
template < typename T >
inline T qobject_cast( QObject *object ){
T dummy;
if( object->inherits( dummy->staticMetaObject()->className()) ){
return static_cast< T >( object );
}
return 0;
}
To copy to clipboard, switch view to plain text mode
And the Driver still remains the same for most of its part except that now we can use the cast similar to Qt4 's
#include <qmetaobject.h> // staticMEtaObject used
#include <qpushbutton.h>
#include <qcombobox.h>
#include <qapplication.h>
template < typename T >
inline T qobject_cast
( QObject *object
){ T dummy;
if( object->inherits( dummy->staticMetaObject()->className()) ){
return static_cast< T >( object );
}
return 0;
}
int main( int argc, char *argv[] ){
QComboBox *b
= qobject_cast<QComboBox
*>
( obj
);
if( b ){
qDebug( b->name() );
}else {
qDebug( "Could not typcast ");
}
return 0;
}
#include <qmetaobject.h> // staticMEtaObject used
#include <qpushbutton.h>
#include <qcombobox.h>
#include <qapplication.h>
template < typename T >
inline T qobject_cast( QObject *object ){
T dummy;
if( object->inherits( dummy->staticMetaObject()->className()) ){
return static_cast< T >( object );
}
return 0;
}
int main( int argc, char *argv[] ){
QApplication app( argc, argv );
QObject *obj = new QPushButton(0, "Name");
QComboBox *b = qobject_cast<QComboBox*>( obj );
if( b ){
qDebug( b->name() );
}else {
qDebug( "Could not typcast ");
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks