"enableAll()" could be a template method:
class MyClass ... {
protected:
template< typename T >
void enableAll( QList<T*>& widgets ){
foreach( T * t, widgets ){
t->setEnabled(true);
}
}
};
class MyClass ... {
protected:
template< typename T >
void enableAll( QList<T*>& widgets ){
foreach( T * t, widgets ){
t->setEnabled(true);
}
}
};
To copy to clipboard, switch view to plain text mode
You can use it like any other method now:
QList<QWidget*> widgets;
QList<QLineEdit*> lineEdits;
enableAll(widgets);
enableAll(lineEdits);
QList<QWidget*> widgets;
QList<QLineEdit*> lineEdits;
enableAll(widgets);
enableAll(lineEdits);
To copy to clipboard, switch view to plain text mode
If you use it with a type that does not have "setEnabled()" method, you will get a compile time error.
----
edit:
I think VC++ does not support member template methods, I'm using gcc, its supported there. If you are using a compiler which does not support this feature, just make this method a regular template (not a member of a class).
----
@down:
ok, my mistake
Bookmarks