PDA

View Full Version : Getting parent dialog variable value in child dialog



subrat17june
7th June 2013, 05:52
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.

Lykurg
7th June 2013, 06:57
You can define a setter-method or pass pValue as an argument to the constructor of the child dialog.

subrat17june
7th June 2013, 07:29
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??

ChrisW67
7th June 2013, 08:01
where have i written wrong??
You forgot your
tags.
You retyped rather than copy-and-pasted your code. I will try to ignore the obvious syntax errors.

This:


explicit ChildDialog(const QString value, QWidget *parent = 0) : QDialog(parent), path(value) {}

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:


ChildDialg::ChildDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ChildDialog)
{
}

giving you the self descriptive error:


Prototype for ChildDialog::ChildDialog(QWidget*) does not match any in class ChildIDialog

subrat17june
7th June 2013, 08:10
changed it now..

//in header file


public:
QString fPath
explicit ChildDialog(const QString value, QWidget *parent = 0) ;



ChildDialg::ChildDialog(QString value,QWidget *parent) : QDialog(parent),fPath(value) ui(new Ui::ChildDialog)
{
}



now i am getting the error
multiple definition of ChildDialog::ChildDialog(QString,QWidget*)
using the statements below to launch the ChildDialog in my maindialog


QString pValue;
ChildDialog = new ChildDialog(pValue,this);
ChildDialog->exex();


what went wrong here?

Lykurg
7th June 2013, 08:21
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.

subrat17june
7th June 2013, 08:23
Really sorry for that...
needed a quick answer so had posted in both the forums