1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| { QStandardItemModel *model = new QStandardItemModel(0, 4,this);
model->setHeaderData(0, Qt::Horizontal, tr("Nom"));
model->setHeaderData(1, Qt::Horizontal, tr("prenom"));
model->setHeaderData(2, Qt::Horizontal, tr("telephone"));
model->setHeaderData(3, Qt::Horizontal, tr("localisation"));
QDomDocument dom("mon_xml");
QFile file("client.xml");
if (!file.open(QIODevice::ReadOnly))
return;
if (!dom.setContent(&file))
{
file.close();
return;
}
file.close();
QDomElement racine = dom.documentElement();
racine = racine.firstChildElement();
int l=0;
while(!racine.isNull())
{
int c=0;
if(racine.tagName() == "client")
{
QDomElement unElement = racine.firstChildElement();
while(!unElement.isNull())
{
if(unElement.tagName() == "nom")
{
QString strNom = unElement.text();
QStandardItem *item = new QStandardItem();
item->setText(strNom);
model->setItem(l,c,item);
}
else if(unElement.tagName() == "prenom")
{
QString strPrenom = unElement.text();
QStandardItem *item = new QStandardItem();
item->setText(strPrenom);
model->setItem(l,c,item);
}
else if(unElement.tagName() == "telephone")
{
QString strTelephone = unElement.text();
QStandardItem *item = new QStandardItem();
item->setText(strTelephone);
model->setItem(l,c,item);
}
else if(unElement.tagName() == "localisation")
{
QString strLocalisation = unElement.text();
QStandardItem *item = new QStandardItem();
item->setText(strLocalisation);
model->setItem(l,c,item);
}
c++;
unElement = unElement.nextSiblingElement();
}
}
racine = racine.nextSiblingElement();
l++;
}
ui.tableView->setModel(model);
ui.tableView->resizeColumnsToContents();
ui.tableView->resizeRowsToContents();
} |
Partager