[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:
Code:
QT_BEGIN_NAMESPACE
class Ui_generalWindow
{
public:
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
Re: [Qt Designer] How to get source code
the code is ok ...to use it use :
Code:
{public:
private:
Ui::MainWindow *ui;
};
MainWindow
::MainWindow(QWidget *parent
){ ui->setupUi(this);
}
ore however your program needs it..
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..
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.
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.