QTableView does not show data
My initialization code calls the checkPrefs()
The view does appear on the desktop.
Debug statements show that the model has the correct data from the table in the correct database. Debug shows no database errors. 'open' is = "Y" and 'log' is not empty. But, the view on the desktop has no data showing in it.
What could be wrong?
Code:
model->setTable("log");
model->select();
}
view->setModel(model);
view->setWindowTitle(logTitle);
return view;
}
void MainWindow::checkPrefs() {
ControlDB ctrl;
QString open
= ctrl.
getOpenLastLog();
if (open == "Y") {
if (log != "") {
Connection conn;
bool base = conn.createConnection(logName);
initializeModel(&model);
model.select();
view1->show();
}
}
}
Re: QTableView does not show data
It looks like your QSqlTableModel (line 24) is declared on the stack and goes out of scope before the view gets a chance to do anything with it.
Re: QTableView does not show data
If I put debug lines after the view1->show() I get the following:
&model is QSqlTableModel(0x22fc10)
view->model is QSqlTableModel(0x22fc10)
So shouldn't the model still exist?
The code I used came almost exactly from a Qt Example, here: http://doc.trolltech.com/4.5/sql-tab...model-cpp.html
Re: QTableView does not show data
try this
Code:
...
initializeModel(model);
model->select();
view1->show();
...
ChrisW67 is right.
Re: QTableView does not show data
:D
Thanks folks. It works great now.