qt_gotcha
7th July 2009, 06:43
Fooling around with the treemodel, I hoped this would work. I want to wrte the contents of the treemodel in the simpletreemodel example to a text file. I thought the index function would get the correct data from the child items if the column counter > 0, so that the contents of the children are simply accessible with model.data(i,j). All I get is a list of contents of the parent items (so at index i,0) , I cannot acces the content of the children.
QFile fout("some.txt");
fout.open(QIODevice::ReadWrite);
for (int i = 0; i < model.rowCount(); i++)
{
QString S = "";
for (int j = 0; j < model.columnCount(); j++)
{
QVariant d = model.data(model.index(i,j),0);
S = S + d.toString()+";";
}
S = S + "\n";
QByteArray line(S.toAscii());
fout.write(line);
}
fout.close();
my reasoning is not correct obviously, but I don't get it. Thanks
QFile fout("some.txt");
fout.open(QIODevice::ReadWrite);
for (int i = 0; i < model.rowCount(); i++)
{
QString S = "";
for (int j = 0; j < model.columnCount(); j++)
{
QVariant d = model.data(model.index(i,j),0);
S = S + d.toString()+";";
}
S = S + "\n";
QByteArray line(S.toAscii());
fout.write(line);
}
fout.close();
my reasoning is not correct obviously, but I don't get it. Thanks