Results 1 to 7 of 7

Thread: accessing widgets in the source code

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    59
    Thanked 1 Time in 1 Post

    Default accessing widgets in the source code

    Hi,
    I'm just learning Qt designer.
    I installed the Qt plugin to create a new Qt project in visual studio.
    I created a simple gui with designer dragging some widgets.
    In the generated code there is a
    Qt Code:
    1. ui.setupUi(this);
    To copy to clipboard, switch view to plain text mode 
    routine.
    Seems that every time I have to access to some of the qt widgets by code I have to prepend the "ui." prefix or I'm doing something wrong?

    For example with designer I dragged on the form a QLabel, then I called it label.
    If I would call some of the QLabel methods I have to write ui.label->setText( bla bla ) ?

    Or the is something wrong in my logic? I don't like the idea of write ui. before every widget.
    I hope to be wrong.

    Best
    Franco Amato

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: accessing widgets in the source code

    The idea is encapsulation - all ui objects belong to an object called 'ui' so you don't mix them with your non-ui objects.

    However, if you prefer them mixed, you can always use multiple inheritance.

    If you don't know how to do that, an example is here: http://doc.trolltech.com/4.3/uitools...heritance.html

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

    Default Re: accessing widgets in the source code

    with regards to the original question, I have the same problem but i don't mind typing the ui. The only true problem i have is that i don't see the widgets eg lable in the header file, when i use qt 4.is there anyway to get them in the header or source file constructor, so i can see all the variable/widgets on a form?

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: accessing widgets in the source code

    I don't get what you mean. All widgets are in the appropriate header file in the 'ui' namespace.

  5. #5
    Join Date
    Jan 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: accessing widgets in the source code

    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3.  
    4. #include <QtGui/QDialog>
    5.  
    6. namespace Ui
    7. {
    8. class Dialog;
    9. }
    10.  
    11. class Dialog : public QDialog
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. Dialog(QWidget *parent = 0);
    17. ~Dialog();
    18.  
    19. private:
    20. Ui::Dialog *ui;
    21. };
    22.  
    23. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 

    This is the header file for a form I created using Qt 4 creator, on the form i have two push Button and a Lable, in the ui file, but none of the widgets are shown in the header file, nor the source file. Please help, i am using qt 4 creator,
    Last edited by wysota; 19th January 2010 at 12:06.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: accessing widgets in the source code

    Quote Originally Posted by viper View Post
    This is the header file for a form I created using Qt 4 creator,
    No, this is a header file for a widget.

    on the form i have two push Button and a Lable, in the ui file, but none of the widgets are shown in the header file, nor the source file.
    As you said yourself - they are in the ui file (or the file generated from it to be precise, it's called ui_nameofyouruifile.h).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: accessing widgets in the source code

    Thanks a lot for your help, I search for the file you mentioned and found it, The thing is i was viewing the project files, so i just change the view to file system. sorry for posting in here

Similar Threads

  1. Where is the source code?
    By Fletcher in forum Newbie
    Replies: 1
    Last Post: 10th December 2009, 21:45
  2. Source code
    By afflictedd2 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2008, 10:04
  3. source code
    By Colx007 in forum Newbie
    Replies: 5
    Last Post: 19th December 2007, 10:15
  4. Qte source code
    By Gaurav vyas in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 1st July 2007, 15:11
  5. Making source code available
    By vermarajeev in forum General Discussion
    Replies: 1
    Last Post: 29th June 2007, 23:01

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
  •  
Qt is a trademark of The Qt Company.