0

I am using a QMessageBox to warn the user if he pressed Delete button by mistake. when the user press Ok button in the QMessageBox, a function is called to delete a row from QTableView (that is connected to a database). after the deletion, the QTableView should be refreshed and the new data (without the deleted row) should be shown.

now, when the user hits Delete button, the warning QMessageBox appears. then, when he presses Ok, the row is deleted from the QTableView. at this point I expect the QMessageBox to disappear, and the new refreshed version of the QTableView to be shown which is not happening !!. instead the QMessageBox appears again and the refresh has to be manually done (as I am just starting the application ) .. why is this happening ?

here is my code:

QMessageBox msg;
msg.setIcon(QMessageBox::Warning);
msg.setText("Delete");
msg.setInformativeText("continue ?");
msg.setDetailedText("Delete permanently");
msg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msg.setDefaultButton(QMessageBox::Cancel);

int ret = msg.exec();
if(ret == 1024){
    msg.Close;
    deleteDataBaseRecord(); // connect to server and delete DB data which is then show the QTableView again
}
else {
    msg.Close;
}
hashDefine
  • 1,491
  • 6
  • 23
  • 33

2 Answers2

0

You don't have () on your Close calls... is this really C++ ?

Don't use the keywords (delete) as function names.

Also, don't use constants (1024) when there are names available.

rivimey
  • 921
  • 1
  • 7
  • 24
  • 1- there is no any() in the Close, and yes it c++. 2- I put "Delete" for simplicity but it is called something else in the actual code. 3- I can't change the returned int, it is already defined as when you press OK you will get int 1024 and I am just using it – hashDefine Jun 17 '13 at 14:05
0

You should call msg.close() (without the capital C) to close msg message box.

Additionally the return value of QMessageBox::exec() method can be QMessageBox::Ok if the OK button that was clicked. Actually, QMessageBox::Close (in your case msg.Close) can be one of those buttons.

hluk
  • 5,848
  • 2
  • 21
  • 19