i am building a small project having following slot :-
Qt Code:
  1. void DialogMemberAdd::query(QString *qry, int flag)
  2. {
  3. QString sql = *qry;
  4. QString str;
  5. QSqlQuery qry2;
  6. qry2.prepare(sql);
  7.  
  8. if(ui->lineEditName->text().isEmpty())
  9. {
  10. //str = "NULL";
  11. return;
  12. }
  13. else
  14. {
  15. str = ui->lineEditName->text().trimmed();
  16. }
  17. qry2.bindValue(0, str) ;
  18.  
  19. int cardno = 0;
  20. if(ui->lineEditCardNumber->text().trimmed().isEmpty())
  21. {
  22. cardno = 0;
  23. }
  24. else
  25. {
  26. cardno = ui->lineEditCardNumber->text().trimmed().toInt();
  27. }
  28. qry2.bindValue(1, cardno);
  29.  
  30. QString addr;
  31. if(ui->lineEditAddress->text().trimmed().isEmpty())
  32. {
  33. addr = "";
  34. }
  35. else
  36. {
  37. addr = ui->lineEditAddress->text().trimmed();
  38. }
  39. qry2.bindValue(2, addr);
  40.  
  41. long monum = 0;
  42. if(ui->lineEditMobileNumber->text().trimmed().isEmpty())
  43. {
  44. monum = 0;
  45. }
  46. else
  47. {
  48. monum = ui->lineEditMobileNumber->text().trimmed().toLong();
  49. }
  50. qry2.bindValue(3, monum);
  51.  
  52. float amount;
  53. if(ui->lineEditAmopuntDeposited->text().trimmed().isEmpty())
  54. {
  55. amount = 0.0;
  56. }
  57. else
  58. {
  59. amount = ui->lineEditAmopuntDeposited->text().trimmed().toFloat();
  60. }
  61. qry2.bindValue(4, amount);
  62. long long memno;
  63. if(ui->lineEditMembershipNumber->text().trimmed().isEmpty())
  64. {
  65. memno = 0;
  66. }
  67. else
  68. {
  69. memno = ui->lineEditMembershipNumber->text().trimmed().toInt();
  70. }
  71.  
  72. qry2.bindValue(5, memno);
  73.  
  74. if(qry2.exec())
  75. {
  76. if(flag == 1)
  77. {
  78. QMessageBox::information(this, "insert_into member records ", "Records inserted successfully");
  79. }
  80. else if(flag == 2)
  81. {
  82. QMessageBox::information(this, "insert_into member records ", "Records updated successfully");
  83. }
  84. }
  85. else
  86. {
  87. QMessageBox::critical(this,"insert_into member records ", QString("error = ").append(qry2.lastError().text()) );
  88. }
  89. }
To copy to clipboard, switch view to plain text mode 
and signal is :-
Qt Code:
  1. void query_sql(QString *sql, int flags);
To copy to clipboard, switch view to plain text mode 
here i send this signal as follows :-
Qt Code:
  1. void DialogMemberAdd::on_pushButtonModifyRecord_clicked()
  2. {
  3. QString sql = "update tableMemberRecords set name = ?, cardno = ?, address = ?, mobileno = ?, amountdeposited = ?, membershipno = ?";
  4. flag = 2;
  5. emit query_sql(&sql, flag);
  6. }
To copy to clipboard, switch view to plain text mode 
when running and clicking on pushbutton it shows following error :-
Qt Code:
  1. "Duplicate entry '9630612822' for key 'MobileNo_UNIQUE' QMYSQL3: Unable to execute statement."
To copy to clipboard, switch view to plain text mode 
even it is already having that entry in database.How to get rid of this duplicate entry.