connect(tableView,SIGNAL (clicked()), this, SLOT(on_tableView_clicked(QModelIndex &index)));
void MainWindow::on_tableView_clicked(QModelIndex &index)
{
if(!index.isValid()){
return;
}
QString id=mModel->data(mModel->index(index.row(),0)).toString();
QSqlQuery q;
q.exec(QString("SELECT id_elemento,id_grupo,id_tipo,nombre,descripcion,icono FROM elemento WHERE id_elemento= " + id +";"));
q.first();
QPixmap pixmap;
if(!pixmap.loadFromData(q.value(5).toByteArray())){
labelImg->setText("<b>Error de Imagen</b>");
return;
}
lineCod->setText(q.value(0).toString());
lineGroup->setText(q.value(1).toString());
lineType->setText(q.value(2).toString());
lineName->setText(q.value(3).toString());
textDescription->setPlainText(q.value(4).toString());
labelImg->setPixmap(pixmap);
}
Result when I click on the table
QSqlQuery :: value: not positioned on a valid record QSqlQuery :: value: not positioned on a valid record QSqlQuery :: value: not positioned on a valid record QSqlQuery :: value: not positioned on a valid record QSqlQuery :: value: not positioned on a valid record QSqlQuery :: value: not positioned on a valid record QSqlQuery :: value: not positioned on a valid record