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. How to change ui something from different class

How to change ui something from different class

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 2 Posters 2.2k Views
  • 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.
  • B beqa

    Hi

    void Tunnelqtworking::on_actionResidual_triggered()

    {

    dif.Residual();   // solving
    
    ResidualForm res;     // different class object 
    res.update_data();    // update this data
    

    }

    void ResidualForm::update_data() // this update_data()
    {
    ....

    ui.lcdNumber->display(r1);
    ui.lcdNumber->update();
    

    }

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #4

    @beqa
    Well, ResidualForm res; is a local variable and it will deleted as soon as
    on_actionResidual_triggered ends so it only be shown on screen for a very short time.

    Try to new it

    ResidualForm *res= new ResidualForm(this); // use this to give it a parent, else you leak
    res->update_data(); // update this data
    res->show();

    Also is ResidualForm ment to be a Dialog and popup or how was it planned to be shown ?
    You are not inserting it into anything.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      beqa
      wrote on last edited by
      #5

      I have tried signal and slot, but has not worked.
      I emit like this

      void Tunnelqtworking::on_actionResidual_triggered()
      {
      dif.Residual(); // solving

      ResidualForm res; // different class object
      emit update_data(5); // I figured out ,that it needs a parameter
      }
      but in ResidualForm i can't create Tunnelqtworking object, its big and give me unclear errors

      mrjjM 1 Reply Last reply
      0
      • B beqa

        I have tried signal and slot, but has not worked.
        I emit like this

        void Tunnelqtworking::on_actionResidual_triggered()
        {
        dif.Residual(); // solving

        ResidualForm res; // different class object
        emit update_data(5); // I figured out ,that it needs a parameter
        }
        but in ResidualForm i can't create Tunnelqtworking object, its big and give me unclear errors

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @beqa

        What should ResidualForm res; do ?
        It will die there.
        So this can never work if its any kind of window.

        You want it to popup there ?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          beqa
          wrote on last edited by
          #7

          I have tabWidget and add this widget
          ui.tabWidget->addTab(new ResidualForm(), "Residual");

          1 Reply Last reply
          0
          • B Offline
            B Offline
            beqa
            wrote on last edited by
            #8

            I take ResidualForm *res in my .h;
            and definit res = new ResidualForm(this);
            but nothing change

            1 Reply Last reply
            0
            • B Offline
              B Offline
              beqa
              wrote on last edited by
              #9

              i try on debug and it enter ordinary this update_data function, but dont change ui element. Seems, ui has restriction from outside

              mrjjM 1 Reply Last reply
              0
              • B beqa

                i try on debug and it enter ordinary this update_data function, but dont change ui element. Seems, ui has restriction from outside

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @beqa
                well in this case, you should NOT make a new one. you should
                use the one you insert.

                ui.tabWidget->addTab(new ResidualForm(), "Residual");

                --->

                ResidualForm *res; // THIS IN H

                and u add it
                res=new ResidualForm()
                ui.tabWidget->addTab(res, "Residual");

                so its the same.
                res->update_data() is for the same shown on screen.

                Do NOT create new one as its not related to the one shown on screen.

                So the error is. You insert one , you see on screen.
                Then you create a SECOND one that you update but its never shown on screen.

                1 Reply Last reply
                2
                • B Offline
                  B Offline
                  beqa
                  wrote on last edited by
                  #11

                  THANK YOU, YOU ARE WELCOME. ITS WORK.
                  Differently, I wonder is it possible to change different class's ui?

                  mrjjM 1 Reply Last reply
                  1
                  • B beqa

                    THANK YOU, YOU ARE WELCOME. ITS WORK.
                    Differently, I wonder is it possible to change different class's ui?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    @beqa said in How to change ui something from different class:

                    , I wonder is it possible to change different class's ui?

                    They are private for the reason, that one should not directly access another's Windows
                    widgets.
                    But you can move it to public and you can access ui-> from outside but this leads
                    to bad code and not a good idea.
                    Its much better to provide function the outside can use
                    Like your update_data

                    If you allow the outside to know the inner details of other classes, you get spaghetti code and
                    a little change will result in many other changes in rest of program.

                    1 Reply Last reply
                    2
                    • B Offline
                      B Offline
                      beqa
                      wrote on last edited by
                      #13

                      thanks, you are very Helpfull

                      1 Reply Last reply
                      1

                      • Login

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