Why do not they load the data from the table in the QLineEdit?

0
 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

    
asked by Antonio Veloso Gomez 02.05.2017 в 12:12
source

1 answer

0

With this line of code I solved my problem:

connect(tableView,SIGNAL (clicked(const QModelIndex &)), this, SLOT (on_tableView_clicked(const QModelIndex &)));
    
answered by 03.05.2017 в 10:26