Results 1 to 7 of 7

Thread: Getting parent dialog variable value in child dialog

  1. #1
    Join Date
    May 2013
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Getting parent dialog variable value in child dialog

    I have a parent dialog. and i am launching a child dialog from within the parent dialog. code below

    // inside parent dialog
    QString pValue;
    ChildDialog = new ChildDialog(this);
    ChildDialog->exex();


    // inside child dialog
    QString cValue = need to get the value of pValue declared in parent dialog.

    i want to pass the value of a QString value from the parent dialog to child dialog..
    how can i access the QString value in my ChildDialog???
    how can i pass/ access the value from the parent dialog ??

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Getting parent dialog variable value in child dialog

    You can define a setter-method or pass pValue as an argument to the constructor of the child dialog.

  3. #3
    Join Date
    May 2013
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Getting parent dialog variable value in child dialog

    well i have done so...

    but getting some errors.

    // in header
    class ChildDialog : public QDialog
    {
    Q_OBJETC
    public: QString path;
    explicit ChildDialog(const QString value, QWidget *parent = 0) : QDialog(parent), path(value){}
    ~ChildDialog();
    }

    //in cpp file
    ChildDialg::ChildDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ChildDialog)
    { ui->SetupUi(this);
    }

    Showing error, prototype for ChildDialog::ChildDialog(QWidget*) does not match any in class ChildIDialog

    where have i written wrong??

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Getting parent dialog variable value in child dialog

    Quote Originally Posted by subrat17june View Post
    where have i written wrong??
    You forgot your [code][/code] tags.
    You retyped rather than copy-and-pasted your code. I will try to ignore the obvious syntax errors.

    This:
    Qt Code:
    1. explicit ChildDialog(const QString value, QWidget *parent = 0) : QDialog(parent), path(value) {}
    To copy to clipboard, switch view to plain text mode 
    gives a declaration and (empty) definition of a constructor requiring one or two arguments.

    This tries to define a constructor that is not declared anywhere:
    Qt Code:
    1. ChildDialg::ChildDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ChildDialog)
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 
    giving you the self descriptive error:
    Qt Code:
    1. Prototype for ChildDialog::ChildDialog(QWidget*) does not match any in class ChildIDialog
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    May 2013
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Getting parent dialog variable value in child dialog

    changed it now..

    //in header file
    Qt Code:
    1. public:
    2. QString fPath
    3. explicit ChildDialog(const QString value, QWidget *parent = 0) ;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. ChildDialg::ChildDialog(QString value,QWidget *parent) : QDialog(parent),fPath(value) ui(new Ui::ChildDialog)
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 

    now i am getting the error
    multiple definition of ChildDialog::ChildDialog(QString,QWidget*)
    using the statements below to launch the ChildDialog in my maindialog
    Qt Code:
    1. QString pValue;
    2. ChildDialog = new ChildDialog(pValue,this);
    3. ChildDialog->exex();
    To copy to clipboard, switch view to plain text mode 

    what went wrong here?

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Getting parent dialog variable value in child dialog

    https://qt-project.org/forums/viewthread/28580/

    Well, it is not polite to waste peoples time. How about only ask at one place and wait for answers? This way several people waste time on writing similar answers. I'm out.

  7. #7
    Join Date
    May 2013
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Getting parent dialog variable value in child dialog

    Really sorry for that...
    needed a quick answer so had posted in both the forums

Similar Threads

  1. how can dialog access variable from parent MainWindow?
    By krezix in forum Qt Programming
    Replies: 5
    Last Post: 30th April 2012, 00:20
  2. How to access objects of parent Dialog from Child Dialog .
    By ranjit.kadam in forum Qt Programming
    Replies: 4
    Last Post: 18th April 2011, 06:39
  3. closing child dialog closes parent dialog
    By sparticus_37 in forum Newbie
    Replies: 2
    Last Post: 28th May 2010, 19:46
  4. Replies: 1
    Last Post: 24th May 2010, 18:56
  5. How to blur parent dialog when child dialog is displayed
    By abhilashajha in forum Qt Programming
    Replies: 4
    Last Post: 10th June 2009, 13:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.