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 .
Forum Updated to NodeBB v4.3 + New Features

How to access objects of parent Dialog from Child Dialog .

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

    [quote author="imrrk" date="1302951509"]hey i know andre,and i can do it,but in I am not understanding it in qt framework,so I asked it..
    [/quote]

    The reason why I recommend you get yourself some basic knowledge, is that this question has nothing to do with Qt itself. You will run into the exact same issue in any framework and in any language. That's why I think you lack some basic knowledge to be an effective programmer.

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

      ok andre,thanks for your advice,hey i i have tried something,just check out my code,
      @#include "dialog.h"
      #include "ui_dialog.h"
      #include<QCalendarWidget>
      #include<QDate>
      #include "dialog1.h"
      #include "ui_dialog1.h"
      #include<QPainter>
      #include <QtGui/QApplication>

      Dialog::Dialog(QWidget *parent) :
      QDialog(parent),
      ui(new Ui::Dialog)
      {
      ui->setupUi(this);

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

      }

      Dialog::~Dialog()
      {
      delete ui;
      }

      void Dialog::showdate(QDate date)
      {
      ui->lineEdit->setText(date.toString());

      }
      

      void Dialog::showset(QDate date)
      {

      if(ui->lineEdit->text()==date.toString())
      {
      Dialog1 a(this);
      connect(&a,SIGNAL(setclicked()),this,SLOT(setcolors()));
      connect(&a,SIGNAL(unsetclicked()),this,SLOT(unsetcolors()));
      a.show();
      a.exec();

      }
      else
      {
      ui->lineEdit->setText("hello");
      }

      }@

      regards
      imrrk

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

        I will be thankful if anyone check out this code and tell me ..

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

          imrrk, if you show us a piece of code, without telling us what to look for, do you really expect a reply? My guess is: it doesn't work as you expect, right?

          Just a hint: you implemented a showset(QDate date) method, but you are not calling it anywhere. I think you should merge the showdate and showset methods into a single method.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vinb
            wrote on last edited by
            #30

            why using:
            a.show and a.exec?

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

              hello andre,u already know what i want,so i showed my code,to show you what i have tried,and you r right ,i forgot to include that line,where i called showset method..

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

                vinb,I have used that to show and execute the dialog

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

                  [quote author="imrrk" date="1303117850"]hello andre,u already know what i want,so i showed my code,to show you what i have tried,and you r right ,i forgot to include that line,where i called showset method..[/quote]

                  Yes, it is clear what you want, but not what might be wrong with the code you show us. That is what I was asking about. I guess it doesn't do what you want, but that's not what you tell us.

                  On the show() and exec() calls. Just remove the show() call please, it is nonsense.

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

                    ok andre,I removed it,what next?

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

                      Do you have introduced a call to showset(QDate date) yet? Or better yet, did you follow my advice on merging that method with showdate(QDate date)?

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

                        i have introduced the call in constructor but also it wont work and do you mean merging in this way

                        @void Dialog::showdate(QDate date)
                        {
                        ui->lineEdit->setText(date.toString());
                        connect(ui->calendarWidget,SIGNAL(activated(QDate)),this,SLOT(showset(QDate)));

                        }
                        void Dialog::showset(QDate date)
                        {
                        Dialog1 a(this);

                        connect(&a,SIGNAL(setclicked()),this,SLOT(setcolors()));
                        connect(&a,SIGNAL(unsetclicked()),this,SLOT(unsetcolors()));
                        a.showNormal();
                        a.exec();
                        }@

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

                          No, no, no!

                          Now you are adding a new connection on each invokation of showdate. You only want one connection between a signal and a slot.

                          Your previous version of showset was almost correct. It looked like this:
                          @
                          //re-formatted for better readability

                          void Dialog::showset(QDate date)
                          {
                          if(ui->lineEdit->text()==date.toString()) {
                          Dialog1 a(this);
                          connect(&a,SIGNAL(setclicked()),this,SLOT(setcolors()));
                          connect(&a,SIGNAL(unsetclicked()),this,SLOT(unsetcolors()));
                          // a.show(); <--- commented out, not needed.
                          a.exec();
                          } else {
                          ui->lineEdit->setText("hello");
                          }
                          }
                          @

                          That was quite close. There is an error in your logic here though. Explore when the else branch will be executed. Only if the date in the lineEdit is not equal to the current date. In response, you then set it to a placeholder text again. So, the next time, this method is executed, it will execute the else branch again.

                          What you would need to do, is remove* this line that sets the hello text. Replace it by a line that sets the current date as the string (line 3 from your last code snippet). Also remove the showDate() method completely (and remove the connect statement that makes a connection to this now removed slot), and in the constructor of your class create a connection like this:

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

                          *) By removing, you get the behaviour that the first time a specific date is clicked, only the text in the line edit is set to the date you just clicked, but all the next times it is clicked the dialog will be shown, until you click another date and the process begins from the start. If you really want to show the dialog only on each second click, you need to re-set the line edit after each time you have shown the dialog, so in the first branch of the if statement.

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

                            thank you very much andre,its working fine...

                            cheers

                            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