ListWidget_ItemSelectionChanged cannot be run more than once?
Hi i am having a problem and cannot figure out how to fix.
I get a list of records displayed in a listwidget, and when a user clicks on a record the below function gets the associated record ID and displays the full record details in a webview. (All this works fine)
When a user reads through the webview they can click a pushbutton to go back to the listwidget where they can click on other records in the list. The problem i am getting is, if the user clicks on the same record as before weird things start to happen.
Initially nothing happens but if i click on the search button (which selects data from database and displays in listwidget), it then takes me to webview. I suspect the itemselectionchanged needs me to select off and then on the original record or on a new unselected record.
Is there anyway around this? Any examples would really help.
Code:
void MainWindow::on_listWidget_itemSelectionChanged()
{
int iRow = ui->listWidget->currentRow();
int strID = persondata.at(iRow)->ID;
persondata.clear();
persondata = dbManager->getPersonData(strID);
//Create instance
PersonData* persondata3;
//Start html tags
//Loop through returned records
foreach(persondata3,persondata)
{
//Add each record to Qstring variable
htmltext.append("<br>");
htmltext.append(persondata3->Address);
}
//End html tags and display in wbeview
htmltext.append("</body></html>");
ui->webView->setHtml(htmltext);
//Go to where webview is displayed
ui->stackedWidget->setCurrentIndex(2);
}
Re: ListWidget_ItemSelectionChanged cannot be run more than once?
I ma having another problem with this function. If i clicked on a record in the listwidget then view webview and then go back to listwidget list and repeat process on another 5 different records the application crashes.
Re: ListWidget_ItemSelectionChanged cannot be run more than once?
Identified the problem,
Code:
int strID = persondata.at(iRow)->ID;
was not able to get an updated value after the initial first click selection this was due to the persondata.clear();