_exp_
6th August 2010, 08:13
When i add a child to model the subsequent offspring overwrites the previous , why??
void MainWindow::addChild()
{
qDebug()<<"Slot activ";
QModelIndex index = ui->treeView->selectionModel()->currentIndex();
QAbstractItemModel *model = ui->treeView->model();
if (model->columnCount(index) == 0) {
if (!model->insertColumn(0, index))
{
return;
}
}
if (!model->insertRow(0, index))
{
return;
}
int column = ui->treeView->selectionModel()->currentIndex().column();
int row=ui->treeView->selectionModel()->currentIndex().row();
model->insertColumn(column , index);
model->setData(model->index(row, column, index), QVariant(linkWWW->text()), Qt::EditRole);
qDebug()<<column;
model->insertColumn(column +1, index);
model->setData(model->index(row, column + 1 , index), QVariant(nameWWW->text()), Qt::EditRole);
qDebug()<<column;
model->insertColumn(column +2, index);
model->setData(model->index(row, column + 2 , index), QVariant(tegWWW->text()), Qt::EditRole);
qDebug()<<column;
model->insertColumn(column +3, index);
model->setData(model->index(row, column + 3 , index), QVariant(tegWWW->text()), Qt::EditRole);
qDebug()<<column;
}
http://s50.radikal.ru/i129/1008/2d/5d114b1fad2et.jpg (http://radikal.ru/F/s50.radikal.ru/i129/1008/2d/5d114b1fad2e.png.html)
the first child added to child_1 child_3
second child added to child_4 child_6
as a result of the second child of the first erased
void MainWindow::addChild()
{
qDebug()<<"Slot activ";
QModelIndex index = ui->treeView->selectionModel()->currentIndex();
QAbstractItemModel *model = ui->treeView->model();
if (model->columnCount(index) == 0) {
if (!model->insertColumn(0, index))
{
return;
}
}
if (!model->insertRow(0, index))
{
return;
}
int column = ui->treeView->selectionModel()->currentIndex().column();
int row=ui->treeView->selectionModel()->currentIndex().row();
model->insertColumn(column , index);
model->setData(model->index(row, column, index), QVariant(linkWWW->text()), Qt::EditRole);
qDebug()<<column;
model->insertColumn(column +1, index);
model->setData(model->index(row, column + 1 , index), QVariant(nameWWW->text()), Qt::EditRole);
qDebug()<<column;
model->insertColumn(column +2, index);
model->setData(model->index(row, column + 2 , index), QVariant(tegWWW->text()), Qt::EditRole);
qDebug()<<column;
model->insertColumn(column +3, index);
model->setData(model->index(row, column + 3 , index), QVariant(tegWWW->text()), Qt::EditRole);
qDebug()<<column;
}
http://s50.radikal.ru/i129/1008/2d/5d114b1fad2et.jpg (http://radikal.ru/F/s50.radikal.ru/i129/1008/2d/5d114b1fad2e.png.html)
the first child added to child_1 child_3
second child added to child_4 child_6
as a result of the second child of the first erased