Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Change Not been reflected

Change Not been reflected

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ManiRonM Offline
    ManiRonM Offline
    ManiRon
    wrote on last edited by ManiRon
    #1

    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 ?
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      ManiRonM 1 Reply Last reply
      1
      • dheerendraD dheerendra

        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.

        ManiRonM Offline
        ManiRonM Offline
        ManiRon
        wrote on last edited by ManiRon
        #3

        @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();
             }
        
        JonBJ 1 Reply Last reply
        0
        • ManiRonM ManiRon

          @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();
               }
          
          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @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?

          1 Reply Last reply
          2
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              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.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              1
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by
                #7

                Are you able to check solution provided. Is this issue resolved ?

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

                ManiRonM 1 Reply Last reply
                0
                • dheerendraD dheerendra

                  Are you able to check solution provided. Is this issue resolved ?

                  ManiRonM Offline
                  ManiRonM Offline
                  ManiRon
                  wrote on last edited by
                  #8

                  @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();
                  
                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved