123456

 

QT学习1 hello程序

 
#define QT3_SUPPORT
#include "hello.h"
#include <QApplication>//在每一个使用QT的应用程序中都必须使用QApplication,它管理了各种
//应用程序的广泛资源,比如默认字体和光标
#include <QPushButton.h>//经典的图形用户界面按钮,QWidget,可以显示一段文本或QPixmap

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);//argc是命令行变量的数量,argv是数组,C、C++特征

    QPushButton hello("hello Qt");//Caption为hello Qt,使用QPushButton(const QString &text, QWidget *parent=0);构造
   
	//-------------------------------------------
	//void QApplication::setMainWidget ( QWidget * mainWidget )
	//设置应用程序的主窗口部件为hello.
	//它退出,程序也退出了,这个好像只能在QT3_SUPPORT定义后使用
	//-------------------------------------------
	a.setMainWidget(&hello);

	//--------------------------------------------
	// Shows the widget and its child widgets. 
	// This function is equivalent to setVisible(true).
	//--------------------------------------------
	//hello.show();//当创建一个窗口部件时,它是不可见的,你必须调用show让它可见   
	hello.setVisible(TRUE);

	return a.exec();//控制转给QT,在exec中,QT接收并处理用户和系统的事件并把它们传给适当的窗口部件
	
}


1.使用QT的应用程序中都必须使用QApplication

2.QApplication::setMainWidget只有在定义了QT3_SUPPORT才能使用

3.主窗口部件退出,程序跟着退出

4.show():让widget和它的子widget都可见,同setVisible(true)

posted on 2011-12-10 14:21  hgy413  阅读(154)  评论(0编辑  收藏  举报

导航