void MainWindow::on_pbFetch_clicked()
{
//ZDataTable* results = new ZDataTable(myDB->FetchSQL(ui->txtQuery->toPlainText()));
// TEST CASE
results->setTable("SystemConfig"); // fails to get fields correctly
if (!results->select())
{
QMessageBox::critical(this,
"Error", results
->lastError
().
text());
QMessageBox::information(this,
"Query", results
->query
().
lastQuery());
}
results
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("ID"));
results
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Name"));
results
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("Value"));
view->show();
// END TEST CASE
}
{
view->setModel(model);
view->setWindowTitle("Result Table");
return view;
}
void MainWindow::on_pbFetch_clicked()
{
//ZDataTable* results = new ZDataTable(myDB->FetchSQL(ui->txtQuery->toPlainText()));
// TEST CASE
QSqlTableModel* results = new QSqlTableModel(this, *myDB);
results->setTable("SystemConfig"); // fails to get fields correctly
results->setEditStrategy(QSqlTableModel::OnManualSubmit);
if (!results->select())
{
QMessageBox::critical(this, "Error", results->lastError().text());
QMessageBox::information(this, "Query", results->query().lastQuery());
}
results->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
results->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
results->setHeaderData(2, Qt::Horizontal, QObject::tr("Value"));
QTableView* view = InitDBView(results);
view->show();
// END TEST CASE
}
QTableView* MainWindow::InitDBView(QSqlTableModel* model)
{
QTableView* view = new QTableView;
view->setModel(model);
view->setWindowTitle("Result Table");
return view;
}
To copy to clipboard, switch view to plain text mode
Bookmarks