PDA

View Full Version : What does this actually mean?



Splatify
23rd March 2011, 15:14
Hi all I have been messing around with QT for some time now, but every single time I copy this line out when creating my dialogs and I actually have no idea what it means...

Therefore, What does this mean?


OpenDialog::OpenDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::OpenDialog)

Ok so first off we are using the OpenDialog Constructor. We're pointing to the parent (what exactly is parent) which is of type QWidget. I think that's right. Ok next up we are inheriting the QDialog class (not to sure what the parent bit means) and then I get confused by the part at the end?

Could someone please explain each part to me... I played around with Qt for a while not, but I think it's time I actually started to learn how it works :D

Thanks for your time and trouble.

stampede
23rd March 2011, 15:18
To understand it, you need to have basic knowledge about constructors in C++, read this one, you may find it useful : C++ constructor initialization list (http://www.cprogramming.com/tutorial/initialization-lists-c++.html)
Then you can apply this knowledge to your dialog example.

FelixB
23rd March 2011, 15:25
well... at first you need to read some C++-tutorials.

what you see is the head of a "constructor" with an "initialization list". The constructor has one parameter, a pointer to a QWidget. this parameter is called "parent". It refers to the parent widget or is NULL if you want to create a custom widget. "QDialog(parent)" does not inherit anything. The class "OpenDialog" is inherited from QDialog. That's why the Constructor of QDialog is called. The next line (3) initializes the member variable "ui" with "new Ui::OpenDialog".