Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of setupUi(this) in Qt

Tags:

qt

I am new to Qt. I have downloaded a source from net.

The header file contains the following

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

       ainWindow>

namespace Ui {
   class MainWindow;
}

class MainWindow : public QMainWindow
{
      Q_OBJECT
      public:
         explicit MainWindow(QWidget *parent = 0);
         ~MainWindow();

      private:
         Ui::MainWindow *ui; // Need for this line. Any one please help
};

#endif // MAINWINDOW_H

in mainwindow.cpp file ui->setupUI(this) has been called in constructor. Please help what is the need for the creation of ui variable

like image 414
Akshara Avatar asked Sep 22 '11 09:09

Akshara


People also ask

What is setupUi in Qt?

setupUi() creates the actual instances of widgets for you. A form that you create in QtDesigner is stored just as XML file.

What is .UI file in Qt?

ui file is used to create a ui_calculatorform. h file that can be used by any file listed in the SOURCES declaration. Note: You can use Qt Creator to create the Calculator Form project. It automatically generates the main.

How do I create a Qt UI file?

To create a . ui file go to File -> New File or Project... In the window that appears select Qt under Files and Classes on the left, then select Qt Designer Form on the right. You'll notice the icon has "ui" on it, showing the type of file you're creating.


1 Answers

You need a MainWindow.ui file which is then processed by Qt's UIC mechanism, which is triggered if you run qmake.

If you are using an IDE like Visual Studio with the Qt Plugin or Qt Creator, just create a new Qt GUI class through the wizard and you will have everything you need.

This page discusses usage of UI files in depth.

like image 152
Tim Meyer Avatar answered Nov 16 '22 04:11

Tim Meyer