// 父子關係--能夠比較其餘語言或框架中的容器子對象等
![](http://static.javashuo.com/static/loading.gif)
#include <QApplication>
![](http://static.javashuo.com/static/loading.gif)
#include <QFont>
![](http://static.javashuo.com/static/loading.gif)
#include <QPushButton>
![](http://static.javashuo.com/static/loading.gif)
#include <QWidget>
int main(
int argc,
char *argv[])
![](http://static.javashuo.com/static/loading.gif)
{
![](http://static.javashuo.com/static/loading.gif)
QApplication app(argc, argv);
//建立應用程序對象
![](http://static.javashuo.com/static/loading.gif)
QWidget window;
//建立窗體對象
![](http://static.javashuo.com/static/loading.gif)
window.resize(200, 120);
//設置大小
![](http://static.javashuo.com/static/loading.gif)
QPushButton quit(
"Quit", &window);
//建立按鈕,以上面的window對象做爲父容器
![](http://static.javashuo.com/static/loading.gif)
quit.setFont(QFont(
"Times", 18, QFont::Bold));
![](http://static.javashuo.com/static/loading.gif)
quit.setGeometry(10, 40, 180, 40);
//設置幾何位置及尺寸,這裏座標(10,40)寬高(180,40)
![](http://static.javashuo.com/static/loading.gif)
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
![](http://static.javashuo.com/static/loading.gif)
window.show();
//顯示窗體
return app.exec();
![](http://static.javashuo.com/static/loading.gif)
}