开发者

How to add items dynamically to QListWidget?

开发者 https://www.devze.com 2023-01-19 23:07 出处:网络
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...

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);  

        }
0

精彩评论

暂无评论...
验证码 换一张
取 消