执行SQLite C ++ Qt更新查询,但不写入数据库文件

时间:2018-07-29 06:59:38

标签: c++ qt sqlite

当我按下按钮时,一切似乎正常,messagebox告诉我查询已成功执行。但是在数据库中,什么都没有改变。 我仍然无法打开和关闭数据库。

connection 'qt_sql_default_connection' is still in use, all queries will cease to work


我遇到两个错误:

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.

但是以同样的方式处理这些错误,我可以将其插入数据库


这是代码:

#include "frmupdate.h"
#include "ui_frmupdate.h"
#include <mainwindow.h>
#include <qsqlquery.h>
#include <qmessagebox.h>

frmUpdate::frmUpdate(QString &cell1, QString &cell2, QString  &cell3, int &index, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::frmUpdate)
{
    ui->setupUi(this);

    ui->lineEdit->setText(cell1);
    ui->lineEdit_2->setText(cell3);
    ui->textEdit->setText(cell2);

    QString st;
    st.setNum(index);
    ui->label_3->setText(st);
    ind = index;
}

frmUpdate::~frmUpdate()
{
    delete ui;
}

void frmUpdate::on_btnUpdate_clicked()
{
    QString Title, Group, Poem;

    Title = ui->lineEdit->text();
    Group = ui->lineEdit_2->text();
    Poem = ui->textEdit->toPlainText();

    MainWindow mainwindow;
    //mainwindow.connOpen();

    QSqlQuery * qry1 = new QSqlQuery(mainwindow.mydb);

    qry1->prepare("update Poems set Title='"+Title+"',Poem='"+Poem+"',Grp='"+Group+"' where ID='"+ind+"' ");


    if(qry1->exec())
    {
        QMessageBox::information(this,tr("ویرایش شعر "),tr("شعر ویرایش شد"));
    }
    else
    {
        QMessageBox::critical(this,tr("ویرایش شعر"),"error");
    }

}

void frmUpdate::on_pushButton_2_clicked()
{
    this->close();
}

0 个答案:

没有答案