just a quick question regarding parent and child relationship. I've been reading tutorials but i can't seem to find any tutorials or readings that demonstrates proper placement of the "this" keyword.
Here is my code:
window::window(){
bar = new QProgressBar;
button = new QPushButton;
bar->setTextVisible(false);
button->setText("IRON LOADER"); //widget
QGridLayout * GL = new QGridLayout(); //layout
GL->addWidget(bar);
GL->addWidget(button);
QGroupBox * gb = new QGroupBox("Group",this); //widget
//second box
QTextEdit * tester = new QTextEdit(); //widget
tester->setFixedHeight(100);
QVBoxLayout * ly = new QVBoxLayout(); //layout
ly->addWidget(tester);
QWidget * widge = new QWidget(this); //widget
//final
widge->setLayout(ly); //first widget group
gb->setLayout(GL); //second widget group
//main wrapper
QGridLayout * test = new QGridLayout;
test->addWidget(widge,0,1);
test->addWidget(gb,0,0);
//set up
QWidget * central = new QWidget;
central->setLayout(test);
setCentralWidget(central); //set central
}
My program is just simple:
it consist of 3 files, namely: window.h
, main.cpp
and window.cpp
and from the windows.cpp
,i inherited QMainWindow
and then i implemented 2 group of widgets:
the left one consist of a QPushButton
and a QProgressBar
.
The right one has a QTextEdit
.
My code compiles and works as intended.
One thing that confuse me is this: when should i put this
? is it alright to not put the this
keyword on some of them(since by the time the parent gets deleted is the same as closing the program) ?
I read that parent / child relationship on qt is about deletion and memory management.