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 ?

  • Qt Champions 2017

    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.



  • @dheerendra

           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();
         }


  • @ManiRon
    I don't get it. You state:

    Data() is the function in which i will disable or enable the menu item .

    You call Data() in your "Working Sequence", you do not call it in your "Not Working Sequence".

    So based on your description what do you expect?


  • Lifetime Qt Champion

    Hi,

    To add to @JonB, you're doing it wrong. You should have your dialog giving some feedback and act on that in your MainWindow class rather than relying on some global state variable for enabling/disabling a menu.


  • Qt Champions 2017

    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.


  • Qt Champions 2017

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

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.