Results 1 to 5 of 5

Thread: [Qt Designer] How to get source code

  1. #1
    Join Date
    Jun 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Question [Qt Designer] How to get source code

    Hi everybody =)
    I'm trying to use Qt Designer to create the source for a couple of widgets, but the code I get is weird, like this:

    Qt Code:
    1. QT_BEGIN_NAMESPACE
    2.  
    3. class Ui_generalWindow
    4. {
    5. public:
    6. QVBoxLayout *verticalLayout;
    7. QGroupBox *groupBox_2;
    8. QVBoxLayout *verticalLayout_3;
    9. QLabel *laberUser;
    10. QLineEdit *textUser;
    11. QLabel *labelAPI;
    12. QLineEdit *textAPI;
    13. QGroupBox *groupBox;
    14. QVBoxLayout *verticalLayout_2;
    15. QLabel *labelKey;
    16. QLineEdit *textKey;
    17. QLabel *labelEmail;
    18. QLineEdit *textEmail;
    19.  
    20. void setupUi(QWidget *generalWindow)
    21. {
    22. if (generalWindow->objectName().isEmpty())
    23. generalWindow->setObjectName(QString::fromUtf8("generalWindow"));
    24. generalWindow->resize(311, 258);
    To copy to clipboard, switch view to plain text mode 

    etc etc..
    Now, while I get how this code works ( I think that object is kind of like an assembly line for my object ), I would prefer getting the code for the actual widget I designed.

    How should I do?
    Thanks in advance! =D

  2. #2
    Join Date
    May 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [Qt Designer] How to get source code

    the code is ok ...to use it use :
    Qt Code:
    1. class MainWindow:public QMainWindow
    2. {public:
    3. MainWindow(QWidget *parent=0);
    4. private:
    5. Ui::MainWindow *ui;
    6. };
    7. MainWindow::MainWindow(QWidget *parent)
    8. :QMainWindow(parent), ui(new Ui::MainWindow)
    9. { ui->setupUi(this);
    10. }
    To copy to clipboard, switch view to plain text mode 


    ore however your program needs it..

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

    Default Re: [Qt Designer] How to get source code

    I understand, it's just that creating two classes for a thing which I will only be using once seemed more like a waste of space and clarity, while having directly a widget class would seem more consistent.

    It would be different if I'd need more of these objects, but I don't..

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [Qt Designer] How to get source code

    In the end, you will have one widget class, the one that have a private member *ui that points to an instance of the class generated by uic.

    It seems odd in the beginning, but trust me it's probably the best method to integrate the design with code, for at least two reasons:
    1) you don't want a designer to change your code when he modify the design
    2) you don't want UIC to change your code when the designer or even you modify the design

    ADVICE: keep the *ui private, you will need to code some functions/slots and declare some signals, but the "extra" work will be for a much better code, and to separate the Designer (UIC generate code) from your manually written code.

  5. #5
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: [Qt Designer] How to get source code

    Or, inherit from the Ui_ class. This makes all of the designer-created methods and objects directly accessible in your derived class, as though they were explicit class members - which they are when you use inheritance.

Similar Threads

  1. Where is the source code?
    By Fletcher in forum Newbie
    Replies: 1
    Last Post: 10th December 2009, 20:45
  2. Source code
    By afflictedd2 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2008, 09:04
  3. source code from Qt4 designer
    By freelancer.kiran in forum Qt Tools
    Replies: 2
    Last Post: 12th May 2008, 07:40
  4. source code
    By Colx007 in forum Newbie
    Replies: 5
    Last Post: 19th December 2007, 09:15
  5. Qte source code
    By Gaurav vyas in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 1st July 2007, 14:11

Tags for this Thread

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.