C++ (Qt) class CommonElement: public QObject{public: explicit CommonElement(QObject*parent = 0); virtual void func() = 0; }; void Base::func(){ qDebug()<<"base";} void Station::func(){ qDebug()<<"station";}//----------------------------------------------------------------------------------------ModelIndex ObjectBrowserModel::index(int row, int column, const QModelIndex &parent) const{ if(!hasIndex(row,column,parent)) return QModelIndex(); CommonElement *parentObj; if(!parent.isValid()) { parentObj = base; } else { parentObj = reinterpret_cast<CommonElement*>(parent.internalPointer()); } parentObj->func(); QObject *obj = parentObj->children().at(row); return createIndex(row,column,obj);} //------------------------------------------------------------- Base*base = new Base; Station *st1 = new Station(base); base->stationList.append(st1); Station *st2 = new Station(base); base->stationList.append(st2);