The code below can only display result sets of 1 of the table(TABLE1 in MYSQL):
model->setQuery("SELECT field1,field2,field3 FROM TABLE1");
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("Field 1"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Field 2"));
model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("Field 3"));
if(model->lastError().isValid())
qDebug() << model->lastError();
view->setModel(model);
view->show();
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("SELECT field1,field2,field3 FROM TABLE1");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Field 1"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Field 2"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Field 3"));
if(model->lastError().isValid())
qDebug() << model->lastError();
QTableView *view = new QTableView;
view->setModel(model);
view->show();
To copy to clipboard, switch view to plain text mode
How to display result sets of 2 tables(TABLE1 and TABLE2 in MYSQL) in one data model?
Bookmarks