PDA

View Full Version : QSQL double insert



abenchaaben
30th January 2017, 17:47
Hi,

I'm working on a project and i'm using Qsql for the first time. I'm trying to insert a data into my database. The problem is that the Click Method that i use to do the insert, i have a messagebox that inform the user that the process is done. With that evry time i click process, i have a double insert into the database. But when i comment the messageBox code, evry thing go well.


void MainFrame::OnProcessStain()
{
QSqlQuery qry;
qry.prepare("INSERT INTO project (user, ) " "VALUES (?)");
qry.addBindValue(username);
qry.exec();

QMessageBox msg1(QMessageBox::Information,"About","Thank you!!!",QMessageBox::Ok);
msg1.setFixedSize(720,720);
QPixmap image1 = QPixmap("zicon1.png");
msg1.setIconPixmap(image1);
msg1.show();
msg1.exec();
QCoreApplication::exit();
}*

Any Help Please.

jefftee
31st January 2017, 07:55
Is your slot being executed twice? i.e. Do you get two messagebox's too or just the insert is executed twice and messagebox only once?

Also, what's the purpose of your line 14 and you seem to have an errant comma in line 4 after the user column. Not sure that would cause an issue, but you are ignoring the return code from qry.exec() too... Check that to ensure it is successful and if not, the look at qry.lastError() to get error details.

abenchaaben
31st January 2017, 08:51
Thank you for answer. I have two insert but only one messageBox. The thing is when i click on my process button i excute the insert statement and i display the messageBox to the user to quit the application (QCoreApplication::exit()).

jefftee
31st January 2017, 19:08
So what about the errant comma after the user column in the INSERT statement and qry.exec() return code? And forgive me for asking, are you sure you don't have another insert statement somewhere else in your code that could be the source of the "double" insert?