I just want to process on database and add the result to a model and send it to another class and view it in GUI. Abstract code is:
I have a public class member:
QSqlQueryModel *model;
Load data and add it to the model and return model:
QSqlQueryModel* PersistenceAdapter::loadServerList(){
cout<<"Loading data"<<endl;
QSqlQuery* qry = new QSqlQuery(db);
qry->prepare("select * from student1.SERVERLIST");
model = new QSqlQueryModel();
model->setQuery(*qry);
return model;
}
In other class I have a load list function. Error is coming from here:
void MainWindow::setServersList(QSqlQueryModel *myModel) {
widget.serverListView->setModel(myModel);
}
Then I call it from constructor of same class and here is code:
MainWindow::MainWindow() {
//Stablish connection to database
PersistenceAdapter *p = new PersistenceAdapter();
setServersList(p->loadServerList());
}
And error is:
RUN FINISHED; Segmentation fault; core dumped; real time: 210ms; user: 10ms; system: 40ms
Appreciate if anyone can help.
widget, and are you sure its serverListView has already been initialized?