0

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.

Dhiraj333
  • 11
  • 3
  • I dont see line number in code, you mentioned line 1, which line is it ? – Kunal Sep 26 '13 at 05:15
  • I have mentioned in the code at creating object of person class. U will see this at the end to the right side. – Dhiraj333 Sep 26 '13 at 05:44
  • check error in device log.. you will findout your issue.. – Niranj Patel Sep 26 '13 at 06:45
  • Its showing this error on IDE console-----Process 15696094 (MessageNew) terminated SIGSEGV code=1 fltno=11 ip=7864de5e(/base/usr/lib/libbbcascades.so.1@_ZN2bb8cascades14GroupDataModel6insertEP7QObject+0x9) mapaddr=0014de5e. ref=00710036 bdslot=1 – Dhiraj333 Sep 26 '13 at 09:25

1 Answers1

1

Error SIGSEGV is generated on segmentation fault.

Therefore I believe m_dataModel is uninitialized.

Konrad Lindenbach
  • 4,911
  • 1
  • 26
  • 28