0

So when I create a new ui project, there is a main.cpp and for example a MainWindow.cpp including a mainwindow.h and ui_mainwindow.h. Where does this MainWindow.cpp get opened when starting the program? It seems like it is just there and QT uses its constructor. QT makes an instance of MainWindow in the main.cpp, but does this automatically include the MainWindow.cpp?

Thanks!

1 Answers1

1

I guess you are creating your first project with Qt. Those are the purpose of each file:

  1. main.cpp: Creates a QCoreApplication and instantiate your QMainWindow class.
  2. mainwindow.h: declares a class that inherits from QMainWindow and forward-declares your UI.
  3. mainwindow.cpp: implements the class declared in the mainwindow.hand instantiates the UI components.
  4. ui_mainwindow.h: that's a generated file which source is the .ui file created for the designer. Check this link for more information.

In the cmake or qmake configuration files, we tell the compiler where to find the different files.

Take a look in this post about why you should never include a cpp file.

mohabouje
  • 3,867
  • 2
  • 14
  • 28
  • Thanks! "In the cmake or qmake configuration files, we tell the compiler where to find the different files." This made it clear for me. :) – displayNamein2019 Mar 18 '19 at 14:25