#ifndef GATHER_H
#define GATHER_H
#include <QList>
#include <QString>
template<class T>
class Gather
{
public:
static QList<T*>& findAll() { return objects_; }
protected:
Gather() { objects_.append((T*)this); }
~Gather() { objects_.removeAll((T*)this); }
private:
static QList<T*> objects_;
};
template<class T>
QList<T*> Gather<T>::objects_;
#endif // GATHER_H
继承了这个模版的类可以通过findall寻找该类的集合.
class className: public QObject, public Gather<MyTimer>
{
}