Results 1 to 5 of 5

Thread: ui class access problem

  1. #1
    Join Date
    Feb 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default ui class access problem

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: ui class access problem

    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.
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Feb 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ui class access problem

    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:n_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

  4. #4
    Join Date
    Feb 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ui class access problem

    got it functioning...(parentWidget ->this....)

    Thanks a thousand time....

  5. #5
    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: ui class access problem

    Maybe I get you wrong but you could simply use: ui->webView4->setUrl().

Similar Threads

  1. How to access the UI from another class ?
    By fitzy in forum Qt Programming
    Replies: 22
    Last Post: 20th July 2016, 15:21
  2. Access a class without using Signals/Slots
    By impeteperry in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2010, 12:14
  3. cannot access QLineEdit text in other methods of the class...
    By Leoha_Zveri in forum Qt Programming
    Replies: 2
    Last Post: 29th September 2009, 13:07
  4. Replies: 4
    Last Post: 26th June 2007, 20:19
  5. Replies: 5
    Last Post: 14th July 2006, 23:42

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.