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. Call method in "parent" window from child window.
Forum Updated to NodeBB v4.3 + New Features

Call method in "parent" window from child window.

Scheduled Pinned Locked Moved General and Desktop
17 Posts 5 Posters 18.5k 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.
  • M Offline
    M Offline
    maxmotor
    wrote on last edited by
    #4

    My windows are sublcasses of QWidget.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #5

      How about:

      You give your child window a signal valueChanged(int theValue);

      You give your parent window a slot (either public or private, whatever you want) changeValue(int)

      At the place where you create the child window (that is: in the parent window), you create a signal-slot connection between the above two.

      In your child window, make sure you emit the valueChanged(int) signal whenever you need.

      Do not try to make the connection directly between a widget on a child window or widget and some internal slot. It is very bad design. Instead, make sure that each part of your application has a good API, and use that.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxmotor
        wrote on last edited by
        #6

        Thank you for your replies!

        I will try your suggestion Andre.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxmotor
          wrote on last edited by
          #7

          I'm not sure if I'm doing this correct?

          @Setup_selectMachine *selectMachine = new Setup_selectMachine();
          QObject::connect(selectMachine, SIGNAL(valueChanged()), this, SLOT(updateValue()));
          selectMachine->show();@

          The above code is where I declare, initialize and show my child window. I've placed the signal-slot connection there as well. "selectMachine" is the name of my child object. "valueChanged()" is the signal in "selectMachine" which should trigger the change. "this" of course refers to this class. "updateValue()" is the slot in this class which I want to be triggered. I am not sending any values directly via the connection, but instead I'm using a resource class which holds all values.

          So - Am I doing it the right way?

          Thank you for your time!

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rahul Das
            wrote on last edited by
            #8

            Well, looks like it is :).. Why dont you give it a try ?


            Declaration of (Platform) independence.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #9

              Looks like a good start, if you actually created that signal and that slot.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maxmotor
                wrote on last edited by
                #10

                Hm - Nothing seems to happen I'm afraid.

                I should mention that my slot method is completely empty. I just use it as a trigger.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #11

                  A slot is not a trigger. A signal is (sort of). The slot should actually do something.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    maxmotor
                    wrote on last edited by
                    #12

                    Oh my mistake. I meant signal. My signal is only a trigger :) Sorry

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #13

                      You do know that you are only supposed to give a declaration of a signal, right? No implementation allowed!

                      So, only do:
                      @
                      //MyChildWindow.h
                      class MyChildWindow: public QDialog
                      {
                      Q_OBJECT
                      /...
                      signals:
                      void valueChanged(int);
                      @

                      Moc will provide an implementation for you.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        maxmotor
                        wrote on last edited by
                        #14

                        Thank you!

                        2 things:

                        1. I did make an empty implementation. Deleted it.
                        2. I forgot to declare it a signal in my header file. ("signals:")

                        I now seems to be working. The variable is not updated properly, but I guess that's due to an error somewhere else.

                        Thank you so much for your time!

                        1 Reply Last reply
                        0
                        • K Offline
                          K Offline
                          KA51O
                          wrote on last edited by
                          #15

                          [quote author="maxmotor" date="1316523853"]I'm not sure if I'm doing this correct?

                          @Setup_selectMachine *selectMachine = new Setup_selectMachine();
                          QObject::connect(selectMachine, SIGNAL(valueChanged()), this, SLOT(updateValue()));
                          selectMachine->show();@[/quote]

                          You forgot to specify the signal and slot parameters types (int).
                          @ @Setup_selectMachine *selectMachine = new Setup_selectMachine();
                          QObject::connect(selectMachine, SIGNAL(valueChanged(int)), this, SLOT(updateValue(int)));
                          selectMachine->show(); @

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            maxmotor
                            wrote on last edited by
                            #16

                            No I did not - to quote myself:

                            [quote author="maxmotor" date="1316523853"]I am not sending any values directly via the connection, but instead I'm using a resource class which holds all values.![/quote]

                            So I don't have to send any parameters with the signal.

                            1 Reply Last reply
                            0
                            • K Offline
                              K Offline
                              KA51O
                              wrote on last edited by
                              #17

                              Sry must have missed that part.

                              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