自学内容网 自学内容网

QSqlQuery::value: not positioned on a valid record


原代码:

    QString sql = QString("select uuid from %1 where uuid = '%2'").arg(TABLE_NAME).arg(uuid);
    qDebug()<<__FILE__<<__LINE__<<" "<<sql;
    QSqlQuery query(getCurrentDatabase());
    if(query.exec(sql))
    {
        qDebug()<<__FILE__<<__LINE__<<" "<<query.value(0).toString();
        return true;
    }
    else
    {
        return false;
    }

出现了上面的错误。

QSqlQuery::value: not positioned on a valid record解决办法-CSDN博客

参考该文章进行修改,问题解决。

    QString sql = QString("select uuid from %1 where uuid = '%2'").arg(TABLE_NAME).arg(uuid);
    qDebug()<<__FILE__<<__LINE__<<" "<<sql;
    QSqlQuery query(getCurrentDatabase());
    if(query.exec(sql))
    {
        if(query.first())
        {
            qDebug()<<__FILE__<<__LINE__<<" "<<query.value(0).toString();
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }


原文地址:https://blog.csdn.net/weixin_51883798/article/details/140321503

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!