How to add items dynamically to QListWidget?
I want to add items dynamically to QListWidget in Qt.
I have used the following piece of code to add items dynamically, but I am able to add only one item in QListWidget...
for(int i=0; i<5; i++)
{
structLocationDetails[i].strlocationName = metaresult["locationName"];
QString strtemp = structLocationDetails[i].strlocationName;
list=new QListWidget(this);
list->setSortingEnabled(true);
list->setGeometry(0,0,190, 450);
QStringList items;
item1=new QListWidgetItem(QIcon(":/imagesIcon.png"),structLocationD开发者_运维问答etails[i].strlocationName,list);
connect(list,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(myitem(QListWidgetItem*)));
}
Here actually I am parsing an XML file and trying to add the parsed xml file contents(locationName) to the QListWidget.
How can I achieve this?
Please provide me any suggestions on this...
Thanks...
changing the code do the job...
list=new QListWidget(this);
list->setSortingEnabled(true);
list->setGeometry(0,0,190, 450);
connect(list,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(myitem(QListWidgetItem*)));
for(int i=0; i<5; i++)
{
structLocationDetails[i].strlocationName = metaresult["locationName"];
item1=new QListWidgetItem(QIcon(":/imagesIcon.png"),structLocationDetails[i].strlocationName,list);
}
精彩评论