Results 1 to 4 of 4

Thread: QSQL double insert

  1. #1
    Join Date
    Jan 2017
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Question QSQL double insert

    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.

    Qt Code:
    1. void MainFrame::OnProcessStain()
    2. {
    3. qry.prepare("INSERT INTO project (user, ) " "VALUES (?)");
    4. qry.addBindValue(username);
    5. qry.exec();
    6.  
    7. QMessageBox msg1(QMessageBox::Information,"About","Thank you!!!",QMessageBox::Ok);
    8. msg1.setFixedSize(720,720);
    9. QPixmap image1 = QPixmap("zicon1.png");
    10. msg1.setIconPixmap(image1);
    11. msg1.show();
    12. msg1.exec();
    13. }*
    To copy to clipboard, switch view to plain text mode 

    Any Help Please.

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QSQL double insert

    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.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3
    Join Date
    Jan 2017
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSQL double insert

    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()).

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QSQL double insert

    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?
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. Replies: 3
    Last Post: 24th April 2016, 07:27
  2. Replies: 0
    Last Post: 31st August 2014, 22:05
  3. QSQL error on insert into statement
    By Cyrebo in forum Qt Programming
    Replies: 3
    Last Post: 29th March 2013, 18:03
  4. Program not finding an existing double in a QList<double>
    By aarelovich in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2011, 21:59
  5. i need to know insert and delete methods in qsql for phone book application
    By gaurav purohit in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 15th September 2009, 15:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.