When we call setupUi()
, we are initializing the form.
What does initializing the form mean? What happens if we don't call it?
Thanks.
When we call setupUi()
, we are initializing the form.
What does initializing the form mean? What happens if we don't call it?
Thanks.
When "setupUi()" is called, all the UI elements that the user put on the form are created. Essentially, UIC tool gets information of what UI elements you put on the form in Qt Designer and generates the code like this for you so you don't need to do that manually:
QPushButton *button1 = new QPushButton(parent);
button1->setText(tr("Start"));
...
QTableView *tableView1 = new QTableView(parent);
...
Are you using Qt Creator? Then press F2 when you are on setupUi()
. See all that code in there? That is what will not happen if you do not call it. It is auto-generated by the form designer.
@user588855, please excuse me if this sounds harsh, but looking at your recent history, it sounds like you are trying to learn Qt without any foundation in C++. I would highly recommend going through a basic primer on C++ first, then you will have a foundational knowledge of classes, inheritance, macros, etc., which will allow you to resolve most of these questions yourself.
Take a look at the ui_[yourFormName].h file that is created by qmake. It basically sets up the User Interface controls that you defined using the designer.
Qt has the wonderful ability to create all the gui elements with C++ code. If you would be a masochist programmer you would do it the same way. However, because we are not all masochists, we use a Qt form designer, and from the gui stuff you see there one of the shipped Qt applications (uic if i'm right) creates C++ code for all the controls you have placed on it. And of course, this code needs to be called, so this is the setupUi... Just check one of your ui_something... files :)