[SOLVED]How to add data into listview from log file
-
Hi
I am very beginer to the Qt development and i faced problemI have a log file and it had some data in that file then i want to display in that data in my listView i try but still i havent proper way to do that this is my code
@
model = new QStringListModel();//Read data from file in the system
QFile file("File path");
QTextStream in(&file);
while(!in.atEnd()){
QString line = in.readLine();
QList<QStandardItem *> items;
QStringList fields = line.split(">");
model->setStringList(fields);}
ui.listView->setModel(model);
@
there are no errors but no data display in a listview please anyone have better idea about that please kindly help me to solve that problem
Thanks
DilukaEdit: please put @ tags around code sections; Andre
-
Thanks for the fast reply andre But still data not display in my listview please can you tell me what steps i want to change and i want to add one item per row i found that method my self i think some steps want to be change but i don't know how to change it
thanks again
-
I found the error my self now data display in listview but my expected out put is not in there after one item display in listview there are huge gap between first and second items in listview any body have better idea about that.
thanks
my current code
@ model2 = new QStandardItemModel();
QFile file(" file name");
file.open(QIODevice::ReadOnly | QIODevice::Text);QTextStream in(&file);
while(!in.atEnd()){
QString line = in.readLine();QList<QStandardItem *> items;
QStringList fields = line.split(">");QStringList fields3 = fields.filter("#");
foreach (QString text, fields3)
items.append(new QStandardItem((QString)text));model2->appendRow(items);
}
ui.listView->setModel(model2); @
!http://tinypic.com/view.php?pic=102tru9&s=6(Error Image )! -
Hi,
You don't check for empty strings when appending items, you might be seeing a result from that.
-
Thank you all problem was solved i got my expected output
correct code
@
model2 = new QStandardItemModel();
QFile file("file name ");
file.open(QIODevice::ReadOnly | QIODevice::Text);QTextStream in(&file);
while(!in.atEnd()){
QString line = in.readLine();QList<QStandardItem *> items;
QStringList fields = line.split(">");QStringList fields3 = fields.filter("#") ; foreach (QString text, fields3) { items.append(new QStandardItem((QString)text)); } if(items.length()>0) { model2->appendRow(items); }
}
ui.listView->setModel(model2);
@
-
Great !
Don't forget to update the thread's title to solved so other forum users may know that a solution has been found