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 access objects of parent Dialog from Child Dialog .
QtWS25 Last Chance

How to access objects of parent Dialog from Child Dialog .

Scheduled Pinned Locked Moved General and Desktop
38 Posts 5 Posters 16.8k 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #4

    imrrk, as you have been told in your calendar thread: the best way is to make sure that you have a clear interface between different objects in your application. That is: don't try to reference (or connect to) internals of one object from another one. Instead, expose the parts you need to expose at the interface of the classes. In this case, that means that your first class (the one with the label) gets a slot setLabel(const QString& text), and that the second class (with the button) gets a corresponding signal. You connect the two at a place where you have references to both the objects. This way, it doesn't matter what happens internally in either class, and you can change that however you like. You can replace the label by some other kind of widget, or you can change the kind of UI you choose for changing it. However, the programming interface: the public slot and signal in the classes's interfaces, can remain the same.

    1 Reply Last reply
    0
    • I Offline
      I Offline
      imrrk
      wrote on last edited by
      #5

      hey gerolf,can u explain me with my example so it will be very clear for me,and I have rightclicked the project and added the new designer form class from which i got dialog1.ui,dialog1.cpp and dialog1.h,so if you u explain with my example above ,i will be very thankful to you..

      regards
      imrrk

      1 Reply Last reply
      0
      • I Offline
        I Offline
        imrrk
        wrote on last edited by
        #6

        hey andre,I am confused,please explain me with short code snippet..

        regards
        imrrk

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #7

          imrrk,

          perhaps you should try to get one of the really good books from the books page of the "wiki":http://developer.qt.nokia.com/wiki/Books_and_Links_for_learning_C_and_advanced_topics and read it. How to make signals and slots and how to make dialogs is basic Qt.

          I suggest this one: Summerfield et.al: C++ GUI Programming with Qt 4

          It explains many of your questions here on dev net and is really god.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • I Offline
            I Offline
            imrrk
            wrote on last edited by
            #8

            Hey i understood the concept...i am clear now.thanks alot

            1 Reply Last reply
            0
            • I Offline
              I Offline
              imrrk
              wrote on last edited by
              #9

              hello ,if I have written same signals for two differnt slots

              @
              connect(ui->calendarWidget,SIGNAL(clicked(QDate)),this,SLOT(showdate(QDate)));
              connect(ui->calendarWidget,SIGNAL(clicked(QDate)),this,SLOT(showset(QDate)));
              @

              and from the theory it is written that it will that slots will be called in order in which they are called,but my case they are getting called at once..so whether i have gone wrong?

              [EDIT: code formatting, Volker]
              regards
              imrrk

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

                Your understanding of what is going on. They are not called at the same time.

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  imrrk
                  wrote on last edited by
                  #11

                  but when i click on calendar widget the slots are getting called at once only

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

                    No, they are NOT. They are called consecutively. First the one, then the other. Why would you think they are called at the same time?

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      imrrk
                      wrote on last edited by
                      #13

                      hello andre,I have taken a calendar widget and text browser in my first dialog,so on click(Qdate )signal ,i have written a slot for showing the text on browser,then again on click(Qdate) I have written one more slot where it opens a new dialog..so when a user clicks for the firsttime a date is displayed in textbrowser,but when he clicks the second time he is directed to new dialog,but in my case both conditions are happening at the same click and not on 2 clicks,

                      regards
                      imrrk

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

                        That is how it should be. You made two connections. Each of the two connected slots are executed for each time the signal is fired. That means that on the first click, you will get both slots executed (in order), and on the second click they will both get executed again.

                        1 Reply Last reply
                        0
                        • I Offline
                          I Offline
                          imrrk
                          wrote on last edited by
                          #15

                          so wats the solution?,but if i want the dialog to be opened only on second click then what we should do

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

                            Re-think your UI so that performing an action on a date will result in the same effect the first time as it does the second time, for instance. I find it weird that you want to display one dialog the one time, and another one the second time. What would happen the third time? Or the tenth?

                            That is: unless your dates display some kind of visual state to differentiate them. But then, that is something you can use for differentiating between the actions you want to perform as well.

                            1 Reply Last reply
                            0
                            • I Offline
                              I Offline
                              imrrk
                              wrote on last edited by
                              #17

                              if we look at std phone calendar,onfirstclick they just show the date,but if we again click the date ,a dialog is opened and we are asked to set reminders,I am asking u that kind of mechanism..

                              regards
                              imrrk

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

                                So, that means that you only do something with a click, if that date is already the selected date. Well... you have access to the selected date, so I suggest you use it.

                                1 Reply Last reply
                                0
                                • I Offline
                                  I Offline
                                  imrrk
                                  wrote on last edited by
                                  #19

                                  ok can u show me by a small code snippet..it will be very helpful

                                  regards
                                  imrrk

                                  1 Reply Last reply
                                  0
                                  • I Offline
                                    I Offline
                                    imrrk
                                    wrote on last edited by
                                    #20

                                    hey whether i should use selectedDate function..?

                                    1 Reply Last reply
                                    0
                                    • I Offline
                                      I Offline
                                      imrrk
                                      wrote on last edited by
                                      #21

                                      hello friends,I have a doubt,Now when i click on any date in calendar widget,I have written slot so as to show the date in a textbrowser as shown in code below
                                      @void Dialog::on_Date_Clicked(QDate date)
                                      {
                                      ui->TextBrowser->setText(date.toString());

                                      }@
                                      Now again when i click on selected date I want to open a newdialog
                                      so on first click it shows the date in browser and on secondclick it should open a dialog..
                                      so how should i proceed..

                                      regards
                                      imrrk

                                      1 Reply Last reply
                                      0
                                      • G Offline
                                        G Offline
                                        giesbert
                                        wrote on last edited by
                                        #22

                                        Create a state machine and handle it there :-)

                                        if you need different actions on the same signals, reconnect to different slot, have some state variables, whatever.

                                        Nokia Certified Qt Specialist.
                                        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

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

                                          [quote author="imrrk" date="1302784064"]hello friends,I have a doubt,Now when i click on any date in calendar widget,I have written slot so as to show the date in a textbrowser as shown in code below
                                          @void Dialog::on_Date_Clicked(QDate date)
                                          {
                                          ui->TextBrowser->setText(date.toString());

                                          }@
                                          Now again when i click on selected date I want to open a newdialog
                                          so on first click it shows the date in browser and on secondclick it should open a dialog..
                                          so how should i proceed..

                                          regards
                                          imrrk[/quote]

                                          Well, one way might be to compare the current content of the text browser with the string representation of the date that was clicked. If they match, then you open the dialog, if they don't, you only set the textual representation of the date in the text browser. Or one of the many, many other ways (most of them better structured than this one) you can do this.

                                          imrrk, this is reall, really basic programming. I would recommend you do some kind of basic programming course, or at least get yourself a good book on the topic at beginners level.

                                          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