How to convert .ui to .h?
-
@StudentScripter said in How to convert .ui to .h?:
. Also i want to see the layout structure i created and so on in my code. Is there a way with form?
You see them, in the generated header. What else is needed? If you want to do everything by yourself then simply don't use ui files.
-
@Christian-Ehrlicher I don't see them in the generated headder. I can access the form by ui->pushbutton usw.
but i don't see it in the headder.
#ifndef DIALOG_H #define DIALOG_H #include <QDialog> namespace Ui { class Dialog; } class Dialog : public QDialog { Q_OBJECT public: explicit Dialog(QWidget *parent = nullptr); ~Dialog(); private: Ui::Dialog *ui; }; #endif // DIALOG_H
#include "dialog.h" #include "ui_dialog.h" Dialog::Dialog(QWidget *parent) : QDialog(parent) , ui(new Ui::Dialog) { ui->setupUi(this); } Dialog::~Dialog() { delete ui; }
Sorry if we're talking past each other.
-
@StudentScripter said in How to convert .ui to .h?:
Also i want to see the layout structure i created and so on in my code. Is there a way with form?
As already mentioned by the others, it makes no sense.
You seem to misunderstand the purpose of the whole QtDesigner/Form-Editor/UI-File stuff...
It is used to not write too much GUI related code or at least simplify the GUI creation/design process.
If you decide to use any*.ui
file, you have to deal with the fact that "product" whichuic
outputs is somewhat static.
Of course you can add or remove stuff by using the pointer to the generated Form class in your actual code. This is recommended and nothing special, but if you do it in the generated header file directy and try to "inject" changes there, every time you re-compile your program (assuming you also re-runuic
) everything in your "Form" header will be overridden since it solely generates the header from the XML style definitions in*.ui
. -
@StudentScripter
You do see everything from your.ui
being processed byuic
. It is theui_dialog.h
you have included which contains that. That is alluic
generates (and you will find it in your build output directory, not your source directory), no.cpp
file. And it makes it so all the widgets you designed live in theUi
namespace. You should welcome that and stick with it, not attempt to change it.And btw: what that means is you will have two classes named
Dialog
: one is the plainDialog
you are creating in your own.cpp
&.h
files, where you can write whatever code you like. The generatedui_....h
file also contains a class nameDialog
but it is in theUi
namespace. And the class memberui
variable is an instance of that. Whose members (your widgets) are accessed viaui->...
, so they do not interfere with anything you write in yourDialog
class.Have a look at the generated
ui_dialog.h
file and everything should become clear. Note that I have told you above which directory that is in. -
@StudentScripter said in How to convert .ui to .h?:
but i don't see it in the headder.
Because you are looking at the wrong header...
If you want to see yourui->pushbutton
in "code", open theui_dialog.h
and have a look, but you should not modify it there.Edit:
@JonB just modified his post and said what you need to know about theui
pointer and the header...I still don't understand why you think you need to do something like this... What's wrong with using the
ui->
pointer to access your generated GUI class? Or just do everything in code and don't use any*.ui
file at all. -
@Pl45m4 Well my idea was: sometimes it's easier to just prototype a quick layout using the form, but for project organisation and total overview of whats going on i like to have everything in code, so when reading the code i directly see which and how many layouts where used.
But before i forget thanks you all for your input. I guess i just stick with writing everything in code in this case.
-
Then simply copy the stuff from setupUi() over to your ctor.
-
@StudentScripter
Like I said, don't forget it's perfectly possible to look inside theui_....h
file to understand/work with it, just like your own code. You can open it inside Creator, and I imagine (can't remember the key press, maybe F2 does it?) directly from the#include "ui_dialog.h"
line. So you really do have the source code there while you're developing. Just don't change anything that is in that file! -
-
@StudentScripter Yes, you can do that. And it shows you how they implemented stuff.