PDA

View Full Version : ui class access problem



marct
24th February 2010, 19:32
Hi,

A really stupid noob/newbie question I guess:
I'm trying to access back a ui component and define some parameters...
Let's take this pseudo code to highlight the issue:

{
QString a = "webview";
ui->a->setUrl(QUrl("http://www.asd....")); //<<< this will error: 'class Ui::websurf' has no member named 'a'
}

Could some one show me an example how to parse a QString variable into the ui?

Thanks in advance.

mcosta
24th February 2010, 20:11
if "ui" refers to a QDesigner form you cannot access elements by name directly.

After you call "setupUi()" the form elements become children of the QWidget you passed to setupUi.

In this case you could use QObject::findChild method to find child by name.

marct
24th February 2010, 20:46
Thanks for the help, so I f i understood correctly I could do this: websurf is the class name ui,

in websurf.cpp:

void websurf::on_details_clicked()
{
QString a = "webView4";
QWebView *bla = parentWidget->findChild<QWebView *>(a); //this give me 2 errors: one is invalid use of menber, and -> is not a pointer
bla->setUrl(QUrl("http://www.bla.com"));

}

this give me 2 errors: one is invalid use of menber
void websurf as been declare as private slot in websurf.h

certainly something not correct I did,

Thanks for your help

marct
24th February 2010, 21:35
got it functioning...(parentWidget ->this....)

Thanks a thousand time....

Lykurg
25th February 2010, 00:32
Maybe I get you wrong but you could simply use: ui->webView4->setUrl().