Hi,
Well, I try to display a part of my SQL Database on a QTableView, simple right ?
Well the problem is the code compiles silently but whenever the signal that should initiate the QTableView is "launched/activated", the app crashes...
When looking at the crash log I finally found that there was a "Bad access error":
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000008
Exception Note: EXC_CORPSE_NOTIFY
Here is the code :
void MainWindow::printTableView()
{
QSqlDatabase db
= connectionArticle
->getDB
();
//Here I retrieve the database connection from an other window if (db.open()){
if (db.databaseName()=="article")
{
query->prepare("SELECT name,type FROM article");
}else{
query->prepare("SELECT name,isWorking,currentArticle FROM journalist");
}
query->exec();
model->setQuery(*query); // When using the debugger, I never pass through this line (it stays here for ever)
}
ui->tableView->setModel(model);
void MainWindow::printTableView()
{
QSqlDatabase db = connectionArticle->getDB(); //Here I retrieve the database connection from an other window
QSqlQuery *query = new QSqlQuery();
if (db.open()){
if (db.databaseName()=="article")
{
query->prepare("SELECT name,type FROM article");
}else{
query->prepare("SELECT name,isWorking,currentArticle FROM journalist");
}
query->exec();
model->setQuery(*query); // When using the debugger, I never pass through this line (it stays here for ever)
}
ui->tableView->setModel(model);
To copy to clipboard, switch view to plain text mode
Well, if anyone knows where I missed I would be glad to know 1
Thank you in advance !
Added after 6 minutes:
Well I figured the little error in the query declaration...
QSqlQuery *query = new QSqlQuery(db);
To copy to clipboard, switch view to plain text mode
But it changes nothing to the problem...
Bookmarks