Skip to content
  • 0 Votes
    5 Posts
    3k Views
    AlbertoA
    Solved. I tried a lot of things to solve the problem. Some of them included calling next before accessing the result as @SGaist said, but it continued saying: QSqlQuery::value: not positioned on a valid record At last I created a new project with a new database and it worked properly with this code: hospital=QSqlDatabase::addDatabase("QSQLITE"); hospital.setDatabaseName("C:/Sqlite3/Hospital.sqlite"); if(hospital.open()){ qDebug()<<"4.Se ha conectado a la base de datos Hospital"; }else{ qDebug()<<"4.ERROR. No se ha conectado a la base de datos Hospital"; } QSqlQuery mostrar; mostrar.prepare("SELECT*FROM Partes WHERE N_Parte=:ID"); mostrar.bindValue(":ID",ui->lineEditN_Parte->text()); if(mostrar.exec()) { qDebug()<<"5.Los datos del parte se han mostrado correctamente"; }else{ qDebug()<<"5.ERROR. Los datos del parte no se han mostrado correctamente"; qDebug()<<"5.ERROR:"<<mostrar.lastError(); } mostrar.next(); ui->tableWidget->setRowCount(15); QStringList Campos; Campos<<"Fecha de Emisión"<<"Unidad Hospitalaria"; ui->tableWidget->setVerticalHeaderLabels(Campos); ui->tableWidget->insertColumn(0); ui->tableWidget->setColumnCount(1); ui->tableWidget->setItem(0, 0, new QTableWidgetItem(mostrar.value(1).toByteArray().constData())); ui->tableWidget->setItem(2, 0, new QTableWidgetItem(mostrar.value(2).toByteArray().constData())); So I guess the problem was in the database, maybe in the columns, maybe in the rows, maybe in the values or maybe in the name of each of them. The important thing is that the code I post in this reply works perfectly, so if anyone has a similar problem I hope it helps. Thank you very much!