Qt_1——HelloWorld

来源:互联网 发布:百科词条优化 编辑:程序博客网 时间:2024/05/29 08:25

打算从这里开始,记录自己在Qt学习之路上写过的程序。就先从HelloWorld开始吧:)

 

      用Qt Creator新建一个Qt C++ Project→Mobile Qt Application,命名为HelloWorld。

      将main.cpp文件代码改为如下:

#include <QtGui/QApplication>

#include <QtGui/QLabel>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QLabel label("Hello,world!");
    label.show();
    return a.exec();
}
      然后运行程序便得到如下图:

关于C++的知识就不赘言了,大家可以翻阅C++相关书籍。

      因为这里用到一个QLabel对象,所以开头引入#include <QLabel>
      程序里用到了QApplication和QLabel两个类,而我们需要包含的头文件名和类名是一样的,这非常方便。
而且大家一定也注意到了,Qt的代码真的非常美丽:)
原创粉丝点击