Cclass Model : public QAbstractItemModel { Q_OBJECT public: Model(QSqlDatabase db, QObject *parent); ~Model(); int columnCount(const QModelIndex & parent = QModelIndex()) const; int rowCount(const QModelIndex & parent = QModelIndex()) const; bool hasChildren ( const QModelIndex & parent = QModelIndex() ) const; QModelIndex parent(const QModelIndex & index) const; Qt::ItemFlags flags(const QModelIndex &index) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; void fetchMore(const QModelIndex & parent); bool canFetchMore(const QModelIndex & parent) const; private: void setupModelData(DObject *parent); QSqlDatabase itsDb; DObject *itsRootItem;} Model::Model(QSqlDatabase db, QObject *parent) : QAbstractItemModel(parent) , itsDb(db){ itsRootItem = new DObject(0, QMap<QString, QVariant>()); setupModelData(itsRootItem);} int Model::columnCount(const QModelIndex & parent) const { return 1;} int Model::rowCount(const QModelIndex & parent) const { DObject *node; if(!parent.isValid()) node = itsRootItem; else node = static_cast<DObject*>(parent.internalPointer()); return node->childCount();} bool Model::hasChildren(const QModelIndex & parent) const { return true;} QModelIndex Model::parent(const QModelIndex & index) const { // ...} Qt::ItemFlags Model::flags(const QModelIndex &index) const { // ...} QVariant Model::data(const QModelIndex & index, int role) const { // ...} QModelIndex Model::index(int row, int column, const QModelIndex & parent) const { // ...} void Model::setupModelData(DObject *parent) { // Тут загружаем чайлды из базы данных parent->setLoaded(true);} void Model::fetchMore(const QModelIndex & parent) { if(!parent.isValid()) return; DObject *parentItem = static_cast<DObject*>(parent.internalPointer()); setupModelData(parentItem);} bool Model::canFetchMore(const QModelIndex & parent) const { if(!parent.isValid()) return false; DObject *parentItem = static_cast<DObject*>(parent.internalPointer()); return !parentItem->childsLoaded();}