The difference between [main] and [mainwindow] in QT Creator

1.3k views Asked by At

I have been learning QT for a month now. I kinda get it but there is one thing that confuses me which is where I write my code. The questions : 1) Is it suppose to be in the main.cpp or the mainwindow.cpp?? I managed to make it work for both cases though. 2) Which one is the better coding practice or have the advantage later in big projects.

Thank you in advance Please post the link of the answer if this has been asked before.

2

There are 2 answers

0
Frank Escobar On BEST ANSWER

Main is just a kind of regular app entry with some inits qApplication init etc.

Mainwindow manages the qApplication until it gets closed, so you should put there anything related to windows appearance, create new widgets etc.

I hope it could help you.

0
Acha Bill On

It depends on what code you write. If you are defining a function of class MainWindow, then do it in mainwindow.cpp.

Code that runs the app and calls the main class is usually in main.cpp.

You definitely write code in both files for any kind of project. Large or small.