PDA

View Full Version : [Qt Designer] How to get source code



Svalorzen
28th June 2010, 22:47
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_BEGIN_NAMESPACE

class Ui_generalWindow
{
public:
QVBoxLayout *verticalLayout;
QGroupBox *groupBox_2;
QVBoxLayout *verticalLayout_3;
QLabel *laberUser;
QLineEdit *textUser;
QLabel *labelAPI;
QLineEdit *textAPI;
QGroupBox *groupBox;
QVBoxLayout *verticalLayout_2;
QLabel *labelKey;
QLineEdit *textKey;
QLabel *labelEmail;
QLineEdit *textEmail;

void setupUi(QWidget *generalWindow)
{
if (generalWindow->objectName().isEmpty())
generalWindow->setObjectName(QString::fromUtf8("generalWindow"));
generalWindow->resize(311, 258);

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

Hardstyle
28th June 2010, 23:25
the code is ok ...to use it use :

class MainWindow:public QMainWindow
{public:
MainWindow(QWidget *parent=0);
private:
Ui::MainWindow *ui;
};
MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent), ui(new Ui::MainWindow)
{ ui->setupUi(this);
}


ore however your program needs it..

Svalorzen
29th June 2010, 10:15
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..

Zlatomir
29th June 2010, 10:26
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.

SixDegrees
29th June 2010, 13:10
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.