qt QSqlQuery::value: not positioned on a valid record

最近用qt开发的时候在用数据库的时候遇到这个问题,根据对象id查询数据的时候出现QSqlQuery::value: not positioned on a valid record,代码如下

 QSqlQuery query( *m_db );
    query.prepare( "SELECT * FROM arce WHERE id = :id" );
    query.bindValue( ":id", id );
    int ret = query.exec();
    if ( !ret ) {
  
  
        qDebug() << "查询数据出错,出错信息:" << query.lastError();
    }
    Arce CheckEntity;
   // while (query.next()) {
  
  
        assemble( &CheckEntity, &query );
  //  }
    return CheckEntity;

把   while (query.next()) {  }   注释打开即可解决问题。

猜你喜欢

转载自blog.csdn.net/fl2502923/article/details/105966068
今日推荐