void MainWindow::createTable(QString tableName, int n) // n - количество строк в таблице.{ QSqlQuery query; QString str = "create table "; str.append(tableName); str.append(" (surname varchar(20) primary key, firstname varchar(20)," " patronymic varchar(20), attendance varchar(20), performance_of_tasks varchar(20))"); if(!query.exec(str)) { qDebug()<<"Unable to create a table"; } for(int i = 1; i <= n; i++) { str = "insert into "; str.append(tableName); str.append(" values('', '', '', '', '')"); query.exec(str); }}
CREATE TABLE table_name (id INTEGER PRIMARY KEY, field1 TEXT, field2 TEXT, ...)
void MainWindow::loadTable(const QModelIndex & index){ QVariant val(model_1->data(index, Qt::DisplayRole)); QString tableName = val.toString(); model_2->setTable(tableName); model_2->setEditStrategy(QSqlTableModel::OnFieldChange); model_2->select(); model_2->setHeaderData(0, Qt::Horizontal, tr("id")); model_2->setHeaderData(1, Qt::Horizontal, tr("family")); model_2->setHeaderData(2, Qt::Horizontal, tr("firstname")); model_2->setHeaderData(3, Qt::Horizontal, tr("patronymic")); model_2->setHeaderData(4, Qt::Horizontal, tr("attendance")); model_2->setHeaderData(5, Qt::Horizontal, tr("performance_of_tasks"));}
view_2->setColumnHidden(0, true);