无法从 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 (将#修改为@)