I want to store some data in database and get this data from it. But when I try to retrieve this data I am having some problem. I have done the following code to read records---
QSqlDatabase database = QSqlDatabase::database();
QSqlQuery query(database);
const QString sqlQuery = "SELECT senderName, msgReceive FROM messageReceive";
if (query.exec(sqlQuery)) {
const int senderNameField = query.record().indexOf("senderName");
const int msgDataField = query.record().indexOf("msgReceive");
int recordsRead = 0;
while (query.next()) {
Person *person = new Person(query.value(senderNameField).toString(),query.value(msgDataField).toString()); //// LINE 1
m_dataModel->insert(person); ///// LINE 2
recordsRead++;
}`
This code is executing well till line 1 , but at line 2 the application is exiting. I have created object of GroupDataModel in .hpp file and given include file also.
Please someone tell me whats the problem here ?
Thanks in advance.