微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法从 qt 中的 SQLITE 检索数据

如何解决无法从 qt 中的 SQLITE 检索数据

代码

    void retrive::on_pushButton_clicked()
{
    QString id=ui->label_id->text();

    MainWindow  log;
    bool ok=log.openconnection();
    if(!ok)QMessageBox::critical(this,"error","Failed to open database");

    QsqlQuery qry;
    qry.prepare("select * from Students where ID='"+id+"'");
    if(qry.exec()){
            ui->NAME_label->setText(qry.value(1).toString());
            ui->CC_label->setText(qry.value(2).toString());
            ui->CGPA_label->setText(qry.value(3).toString());
            ui->MOBILE_label->setText(qry.value(4).toString());
            ui->ADDRESS_label->setText(qry.value(5).toString());
    }else
        QMessageBox::critical(this,qry.lastError().text());

    log.closeconnection();
}

我试图从 qt 中的 sqlite 数据库中检索数据,但它显示以下错误。 我现在该怎么办?

QsqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use,all queries will cease to work.
QsqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection',old connection removed.
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
QsqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use,all queries will cease to work.

我现在能做什么?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。