PDA

View Full Version : ListWidget_ItemSelectionChanged cannot be run more than once?



jins
28th November 2010, 19:41
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.



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
QString htmltext = "<html><body>";

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

}

jins
28th November 2010, 22:34
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.

jins
29th November 2010, 14:16
Identified the problem,
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();