1

When we call setupUi(), we are initializing the form.

What does initializing the form mean? What happens if we don't call it?

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385
  • 2
    this site is not a substitute for **reading the docs**, and trying the samples. Just build a sample Qt app with a ui file according to whatever you're reading, and take that call out. You'll find what happens pretty fast. – Mat Apr 14 '11 at 12:17
  • 1
    -1 for not reading the docs, neither source, nor trying it out for yourself before asking. (If it was only once i'd not have a problem with it. But it must be the 10th question here about Qt initialization or other Qt basics.) – RedX Apr 14 '11 at 12:32

4 Answers4

7

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);
...
Barbaris
  • 1,256
  • 7
  • 7
3

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.

Dave Mateer
  • 17,608
  • 15
  • 96
  • 149
  • 1
    We even have [a guide on recommended introductory C++ books](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) here on Stack Overflow! – In silico Apr 15 '11 at 06:37
2

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.

grayDad
  • 324
  • 1
  • 7
2

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 :)

Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167