我的第一个Qt程序->hello,qt!

hello每次都是伴随之我们学习语言入门的,这个是我学Qt的第一个程序。这个的源代码文件有三个,分别是hello.h,hello.cpp,mian.cpp.

hello.h

  
  
  
  
  1. #ifndef _HELLO_H_ 
  2. #define _HELLO_H_ 
  3. #include<QtGui/QtGui> 
  4. #include<QDialog> 
  5. class hello:public QDialog 
  6.     Q_OBJECT 
  7. public: 
  8.     hello(QWidget* =0); 
  9. }; 
  10. #endif 

hello.cpp

 

  
  
  
  
  1. #include"hello.h" 
  2. #include<QtCore/QTextCodec> 
  3. hello::hello(QWidget* parent):QDialog(parent) 
  4.     QPushButton* closeBtn = new QPushButton(tr("关闭")); 
  5.     QLabel* label = new QLabel(tr("hello,qt!")); 
  6.     label->setFont(QFont("ubuntu",35,QFont::Bold)); 
  7.     QVBoxLayout* dlgLayoutnew QVBoxLayout; 
  8.     dlgLayout->addWidget(label); 
  9.     dlgLayout->addWidget(closeBtn); 
  10.     connect(closeBtn,SIGNAL(clicked()),this,SLOT(close())); 
  11.     setLayout(dlgLayout); 

mian.cpp

 

  
  
  
  
  1. #include<QApplication> 
  2. #include<QDialog> 
  3. #include<QtGui/QtGui> 
  4. #include"hello.h" 
  5. int main(int argc,char* argv[]) 
  6.     QApplication app(argc,argv); 
  7.     QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); 
  8.     hello* test = new hello; 
  9.     test->show(); 
  10.     return app.exec(); 

 效果图:

 

 

你可能感兴趣的:(C++,qt)