Change Not been reflected
-
I have an application in which i will have a menu button and if i press that button i will show a dialog window and perform some operation . and based on the operation i will disable or enable the menu items . But once i close the dialog the menu is not disabled or enabled based on the operation . I will have a gloable variable which i will update from the Dialog based on the operation and i checked whether the the variable is getting updated or not . It is getting updated and based on the global variable i will change the menu items to disabled or enabled in mainwindow but it was not reflecting.
Not Working Sequence : Dialog dd; dd.show(); dd.exec(); Working Sequence : Dialog dd; dd.show(); dd.exec(); Data();Note : Data() is the function in which i will disable or enable the menu item .
Why it works like this ? -
Looked at your description. Too difficult to think/assume what is happening. Can give simple sample to show what you are doing ?
Please note exec() is enough. You don't have to use show and exec together.
-
Looked at your description. Too difficult to think/assume what is happening. Can give simple sample to show what you are doing ?
Please note exec() is enough. You don't have to use show and exec together.
MainWindow s; int S;This is my MainWindow Code:
void MainWindow :: Data() { if(S == 1) { ui->actionData->setDisabled(true); ui->actionMurali->setDisabled(true); ui->actionPatterns->setDisabled(true); } else { ui->actionData->setEnabled(true); ui->actionMurali->setEnabled(true); ui->actionPatterns->setEnabled(true); } } void MainWindow::on_actionDialog_triggered() { Dialog dd; dd.show(); dd.exec(); }This is my code for the dialog
void Dialog::on_pushButton_clicked() { this->close(); S = 1; s.Data(); } void Dialog::on_pushButton_2_clicked() { this->close(); S = 2; s.Data(); } -
MainWindow s; int S;This is my MainWindow Code:
void MainWindow :: Data() { if(S == 1) { ui->actionData->setDisabled(true); ui->actionMurali->setDisabled(true); ui->actionPatterns->setDisabled(true); } else { ui->actionData->setEnabled(true); ui->actionMurali->setEnabled(true); ui->actionPatterns->setEnabled(true); } } void MainWindow::on_actionDialog_triggered() { Dialog dd; dd.show(); dd.exec(); }This is my code for the dialog
void Dialog::on_pushButton_clicked() { this->close(); S = 1; s.Data(); } void Dialog::on_pushButton_2_clicked() { this->close(); S = 2; s.Data(); } -
Y are you trying control enable and disable through S variable. This indicates it is always calling with S=2 for some reason we don't know. Did you check which if condition is it entering (S=1 or S=2) You can split data() as two different functions like enableMenu() and disableMenu(). Call these functions appropriately. As everybody already said, it is best avoid global variable like and make object-to-object communication.
-
Are you able to check solution provided. Is this issue resolved ?
-
Are you able to check solution provided. Is this issue resolved ?
@dheerendra
I tried by creating two functions and calling them to disable or enable based on the button pressed at the dialog window, but its not working . But once if i call the function after the exec of the dialog its working.Dialog dd; dd.exec(); DataDisable();