parent 是父亲控件的指针,而非父类
QDialog是父类
这样说吧
class YourDialog:public QDialog
{
YourDialog(QWidget *parent=NULL):QDialog(parent)
{
label=new QLabel("i will be the son widget of y,and i am the subClass of QFrame");
this->setWindowTitle("i will be son widget of m ,and i am the subClass of QDialog");
}
QLabel *lable;
};
QMainWindow *m new QMainWindow(NULL);
YourDialog *y=new YourDialog(m);
随便写了下,可能有错
这里 y是m的自控件,但是你要如何构建一个y呢?
因为y是从QDialog继承的,所以你要调用它的构造函数,
如果不调用会用默认的构造函数,但是我们一般需要指定一个空间的父控件(widget)
我们把这个父控件的指针作为参数传到其父类(QDialog)构造函数中
所以就有了parent
这里m是没有父控件的
而label的父控件是y