[Qt-interest] Access a dialogue's widgets created with Qt designer from main window?
Ian Thomson
Ian.Thomson at iongeo.com
Wed Feb 10 15:48:50 CET 2010
Hi,
Robert Wood wrote:
> If I create userData with *code* within the server_dialogue.cpp like this:
>
> userData = new QLineEdit(this);
> userData->setGeometry(30,30,120,30);
> userData->show();
>
> Then I can happily get the data in the main window with this line:
>
> QString t = dialogue.userData()->text();
No you can't, calling userData() will cause a compile error because
userData is a QLineEdit pointer. You would just do dialogue.userData->text()
> But this complains about a forward declaration of the structure
> Ui::server_dialogue.
The compiler is not lying to you here. It can't use anything which is
only a forward declaration. You could get round this by including the
headers for the ui file but that is getting messy.
What I recommend is adding a public function in your dialogue code that
returns ui->userData.text()
> Is it possible to do what I want, or do I simply have to hand code the
> widgets in the dialogue?
The ui compiler just generates code for these widgets. Take a look at
the output of uic and you'll see that there is no difference between
hand coded widgets and widgets generated from designer.
Cheers,
Ian.
More information about the Qt-interest-old
mailing list