I'm trying to retrieve data from a QListWidgetItem when I click on the list, but I'm not getting it. I made a custom Widget to list the elements, however although I can not visualize I can not in the click event retrieve my element.
Application click event
void Start::on_phonebookList_itemClicked(QListWidgetItem *item)
{
// ContactListItem *cItem = (ContactListItem*)item;
ContactListItem * cItem = (ContactListItem * )ui->contactPhonebookNumberList->itemWidget(item);
this->contactSelected = cItem->getContact();
ui->contactPhonebookName->setText( this->contactSelected->name.toLatin1().data());
const QVector<PhonebookNumber *> list = this->contactSelected->getNumbers();
for(int i=0;i!=list.size();i++){
PhonebookNumber * pn =list[i];
ui->contactPhonebookNumberList->addItem(pn->number.toLatin1().data());
}
ui->nav->setCurrentIndex(NavigationTabs::CONTACT);
}
Popular to list
void Start::on_Start_onReloadPhonebookListEvent(const PhonebookType & type)
{
if(this->getCurrentPhonebookType() != type){
return;
}
const QVector <PhonebookContact*> list = Phonebook::getInstance()->getPhoobook(type);
this->ui->phonebookList->clear();
for(int i = 0; i!= list.size();i++){
QListWidgetItem *widgetItem = new QListWidgetItem();
this->ui->phonebookList->addItem(widgetItem);
ContactListItem * contactItem = new ContactListItem();
contactItem->setContact(list[i]);
widgetItem->setSizeHint(QSize(contactItem->width(),contactItem->height()));
this->ui->phonebookList->setItemWidget(widgetItem,contactItem);
}
}