PDA

View Full Version : QDirModel curiosity



Caius Aérobus
4th April 2008, 19:08
It appears that QDirModel uses rows to store directory entries, which means that columns are not useful at all. So I have a simple hierarchy:

ls -R

A C

./A:
B

./A/B:

./C:
If I run the following code to browse the hierarchy:

void
MyClass::Browse(QModelIndex idx, int indent)
{
QFileInfo info = this->fileInfo(idx);
for (int i=indent ; i>0 ; i--)
this->Print(" \r");
this->Print("%d %d %s", idx.row(), idx.column(), info.fileName().toAscii().constData());
for (int i=0 ; idx.child(i, 0).isValid() ; i++)
this->ComputeSizes(idx.child(i, 0), indent+2);
}
I get the expected output:

MyClass: 38 0 test
MyClass: 0 0 A
MyClass: 0 0 B
MyClass: 1 0 C
But if I change the code so as to browse columns rather that rows as follow:

void
MyClass::Browse(QModelIndex idx, int indent)
{
QFileInfo info = this->fileInfo(idx);
for (int i=indent ; i>0 ; i--)
this->Print(" \r");
this->Print("%d %d %s", idx.row(), idx.column(), info.fileName().toAscii().constData());
for (int i=0 ; idx.child(0, i).isValid() ; i++)
this->ComputeSizes(idx.child(0, i), indent+2);
}
I get an unexpected output:

MyClass: 38 0 test
MyClass: 0 0 A
MyClass: 0 0 B
MyClass: 0 1 B
MyClass: 0 2 B
MyClass: 0 3 B
MyClass: 0 1 A
MyClass: 0 2 A
MyClass: 0 3 A
I would have expected that idx.child(0, i>0) be unvalid!

I have one more question: what is the difference between QDirModel::sibling() and QDirModel::child()?