PDA

View Full Version : why this program is not working



ramamurthy.kv
8th May 2008, 08:05
can anyone tell why this program is not working?
am not able to see the directory structure.
(from the printf's i could make out that is is not calling parent and data functions. this code doesnt contains printfs)


#include <QtGui>

class TestModel : public QAbstractItemModel
{
public:
QDirModel *model;
TestModel()
{
model = new QDirModel();
}

QVariant data(const QModelIndex &index, int role) const
{
return model->data(index, role);
}

QModelIndex index(int row, int column, const QModelIndex &parent) const
{
return model->index(row, column, parent);
}

QModelIndex parent(const QModelIndex &index) const
{
return model->parent(index);
}

int rowCount(const QModelIndex &parent) const
{
return model->rowCount(parent);
}

int columnCount(const QModelIndex &parent) const
{
return model->columnCount(parent);
}
};

int main(int a, char** b)
{
QApplication app(a, b);
TestModel *mod = new TestModel;
QTreeView view;
view.setModel(mod);
view.show();
return app.exec();
}

Thanks

wysota
8th May 2008, 09:48
The index contains a pointer to the model and it has to match the actual model that is using it, so if you want to pass the index you get to another model, you have to build a new index that references this another model and not yours. And of course your index() and parent() implementations are invalid because of the same reason.

ramamurthy.kv
8th May 2008, 11:37
Thanks Wysota,

but i have no idea as how to build new index or map to another model index. Could you give any reference doc which is explaining this? How difficulty it is?

wysota
8th May 2008, 13:26
Call the model's index() method with appropriate parameters. By the way, I don't know what you are doing, but maybe using QAbstractProxyModel would be easier?