modelObj = new QSqlTableModel(); modelObj->setTable("list_obj"); modelObj->select(); modelObj->setHeaderData(0, Qt::Horizontal, QString::fromUtf8("Название объекта")); modelObj->setHeaderData(1, Qt::Horizontal, QString::fromUtf8("Индикация")); modelObj->setHeaderData(2, Qt::Horizontal, QString::fromUtf8("Картиночка")); ui->ListObj->setModel(modelObj);
void MainWindow::ChildRecordForObj(QModelIndex index){ QVariant rec = modelHard->data(index,1);}
void MainWindow::ChildRecordForObj(QModelIndex index){ QVariant rec = modelHard->index(index.row(), oidColumn).data();}
...modelHard->select();ui->ListHard->setModel(modelHard);...
QVariant MyModel::data(const QModelIndex& index, int role) const{ if (!index.isValid()) return QVariant(); if (role == Qt::UserRole) return _getOid(index); else return QSqlTableModel::data(index, role);}
_getOid(index);
void MainWindow::ChildRecordForObj(QModelIndex index){ QSqlRecord record= modelObj->record(index.row()); QSqlField field = record.field("oid"); int id = field.value().toInt();}
QSqlField field = record.field("name");
model->select()