Iterator overwrites the values in QtreeWidget . My text file contains these three lines and only one line is showing
************text file **************
1200,Shahbaz,Ifc,laja
2001,ali,Step,kdh
1992,ikaka,psp,ayaj
****************************************
Kindly tell me how to avoid it .
My code is following
QString fileName = QFileDialog::getOpenFileName(this, tr ("Open File"), "C:\\", "All files (*.*);; Text File (*.txt);; IFC File (*.ifc);; STEP File (*.step);;XML files (*.xml);;Image files (*.jpg *.png)");
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice ::Text))
QMessageBox::critical(this,tr("STOP"),tr("Error with loading"));
QTreeWidgetItem *item = new QTreeWidgetItem (ui->treeWidget);
QTextStream in(&file);
QString line;
// ui->textBrowser->setText(in.readAll());
do
{
line = in.readLine();
QList <QString> parts = line.split(",", QString::KeepEmptyParts);
QString L;
QListIterator<QString> Iter (parts);
while (Iter.hasNext())
{
for (int i=0 ; i<4; i++)
{
L = Iter.next();
item->setText(i,L);
}
}
} while (!in.atEnd());
}
Bookmarks