转自:http://qt-project.org/forums/viewthread/14782
If we’re throwing around solutions anyway: you could even create a class template that adds this function to any widget you want, including all stock widgets. :-)
-
template < class T >
-
public IDClass <T >: public T {
-
public :
-
m_id (id ) ,
-
T (parent )
-
{ }
-
-
void setId ( int newId ) {m_id = newId } ;
-
int id ( ) const { return m_id ; }
-
-
private :
-
int m_id ;
-
}
-
-
//etc.