[Qt-interest] Access a dialogue's widgets created with Qt designer from main window?

Robert Wood robert.wood at apostrophe.co.uk
Wed Feb 10 15:40:20 CET 2010


I have created a dialogue with Qt designer which has some line edits. I 
am unable to access these in the following way:

server_dialogue dialogue(this);

if (dialogue.exec() == QDialog::Accepted)
	{
	QString t = dialogue.userData()->text();
	}

userData is a line edit that I placed using Qt designer. The auto 
complete doesn't access it and it fails to compile.

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();

I did try moving this:

Ui::server_dialogue *ui;

from private to public in server_dialogue.h and doing this:

QString t = dialogue.ui->userData()->text();

But this complains about a forward declaration of the structure 
Ui::server_dialogue.

Is it possible to do what I want, or do I simply have to hand code the 
widgets in the dialogue?

Many thanks!




More information about the Qt-interest-old mailing list