是KDE 2_Qt编程宝典中的一个例子,有些地方不明白,特此请教。
(1) threewidget.h
#ifndef THREEWIDGET_H
#define THREEWIDGET_H
#include<qpushbutton.h>
#include<qlabel.h>
class threewidget:public QWidget
{
public:
threewidget(QWidget *p=0,const char *name=0);
private:
QPushButton *topButton;
QPushButton *bottomButton;
QLabel *label;
};
#endif // THREEWIDGET_H
(2) threewidget.cpp
#include"threewidget.h"
threewidget::threewidget(QWidget *p, const char *name)
{
setMinimumSize(120,180);
setMaximumSize(120,180);
topButton=new QPushButton("top",this);
topButton->setGeometry(15,15,90,40);
label=new QLabel("love",this);
label->setGeometry(15,70,90,40);
label->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
bottomButton=new QPushButton("bottom",this);
bottomButton->setGeometry(15,125,90,40);
}
(3) main.cpp
#include <QtGui/QApplication>
#include "widget.h"
#include"threewidget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
threewidget w;
w.setGeometry(10,10,100,100);
w.show();
return a.exec();
}
程序的确能正常运行,但有以下不解....
threewidget(QWidget *p=0,const char *name=0)显然是个构造函数,而在main.cpp中却 threewidget w;并没有提供参数,是如何实现初始化的呢?
且topButton=new QPushButton("top",this);this显然是threewidget类型的指针,而且看出现的提示,是指QPushButton中的某个系统默认构造函数吗?
而且我觉得threewidget并没利用参数,所以将其形参表清空后出现如下错误,
undefined reference to `threewidget::threewidget(QWidget*, char const*)'
难度系统早就默认了吗?那如果部件多次嵌套又该怎么办呢?
本人近几天接触的QT,很多不懂,望大家不吝解释下,谢谢。。。