Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOVLED] Puzzling class member and its usage in class constructor
Karen last edited by Karen
I inherited a piece of code as the following:
In the header file:
class MainWindow : public QMainWindow
explicit MainWindow(QWidget *parent = 0);
In cpp file, the class constructor as defined as below:
MainWindow::MainWindow(QWidget *parent) :
Question is why a pointer to itself in the header file? Is this not just "this" as in C++?
Then in the constructor, ui(new Ui::MainWindow) is used in the constructor. What does it do to the constructor?
mcosta last edited by
Hi and welcome to devnet,
'ui' is not an instance of the MainWindow class but of the Ui::MainWindow one that is defined inside the namespace Ui.
Karen last edited by
@mcosta Thank you. Indeed I found the class definition for Ui::MainWindow. So the constructor initializes the member class *ui using ui(new Ui::MainWindow).