Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Newbie Question - Form design or Code?
Uberlinc last edited by
Just starting out with Qt and using Qt Creator 4.4.1 (Based on Qt 5.9)
I'm a little fuzzy on the whole "create in forms/create in code" topic.
So, if I create an object (e.g. button, tickbox, slider etc) in code, it appears, but if I create said object in the form editor, it doesn't create any corresponding code to account for this?
e.g. If I create a slider and a progress bar, I can link the two graphically, but there will be no line of code connecting the signal to the slot?
Is this correct?
If I then go and create something in code, does this play well with the objects created graphically?
Does this mean that, during debug, you must remember what was created on the form and what was created in code so change the details there?
I was watching the videos by VoidRealms on YouTube.
I could have sworn that he created something graphically and then went to change the code that had been magically created as a result of the object that he created.
Am I mistaken?
Is this a mode that you can switch on or off?
Can anyone clear this up for me?
it doesn't create any corresponding code
It does. This is what moc tool is used for. No magic involved :-) Take a look at moc_* files in your build directory after building your project.
Yes code is generated for you. When using designer you get a .ui file that is an XML describing the widgets you are going to use. That file will be processed by
uicto generate the corresponding C++ code.
There's no problem mixing designer created widgets with code create ones.
No you don't, when debugging you'll be able to easily distinguish the debugger shows the variable names so you can easily spot which are yours and which comes from designer.
Don't modify the code generated (moc_ or ui_ files), there are already warnings in them for that. These are generated at compilation time, so don't touch them.
What mode are you thinking about ?
[edit: Fixed wrong naming, thanks @aha_1980 SGaist]
I fully ack what @SGaist said, with the addition that the form files end in .ui and the generated files start with ui_
the compiler is named uic, indeed.
Buckwheat last edited by
I am also in full agreeance with @SGaist!
There is a neat little secret when using form designer and needing connections. You do not need to add signals/slots to the form. Just do the following:
void on_<objectName>_<signal name> (...);
void Class::on_<objectName>_<signal name> (...)
--- do stuff ---
This will automaticly pickup your object and connect the signal/slot. No fuss, no muss.
void on_button_clicked (bool checked);
void Class:on_button_clicked (bool checked)
--- do something ---
This is fun-with-designer 101!