新建工程 -> 选择Qt Gui 应用 然后点击选择

在弹出的对话框中填写名称,创建路径等信息:

点击下一步,选择该工程的编译器.

点击下一步,可以选择生成的主窗口文件.不过这里我们仅仅用简单的示例文件,不勾选"创建界面".

最后一步. 这里询问我们是否添加版本控制.对此我们不需要,选择"无",点击完成即可

这里会生成四个文件:

HelloWorld.pro   文件就是Qt工程文件(project file),由qmake处理,生存make 程序所需要的make file;

main.cpp      里面就是一个main函数,作为程序的入口函数.

mainwindow.cpp

mainwindow.h    两个文件就i是我们曾经指定的文件名的文件

将main.cpp 修改如下

#include "mainwindow.h"
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
//    MainWindow w;
//    w.show();

    QLabel lable("Hello,world");
    lable.show();
    return a.exec();
}

点击 Qt Creater 左侧的绿色运行按钮.

代码分析:

include  是C++的include 语句,引用QApplication 以及QLabel 两个类.

main()函数中第一句是创建一个 QApplication 类实例.对Qt程序来说,main()函数一般以创建application对象开始.后面才开始业务代码.

(GUI程序是QApplication,非GUI程序是QCoreApplication. QApplication 实际上是QCoreApplication 的子类.)

我们创建QApplication对象之后,直接创建一个QLabel对象,构造函数赋值 "Hello,world".

最后调用QLabel的show()函数将其显示处理.

man()函数最后,调用 app.exec(),开启事件循环.可简单理解为一段无限循环.

Qt_HelloWrold的更多相关文章

随机推荐

  1. laravel框架数据迁移

    迁移就像数据库的版本控制,允许团队简单轻松的编辑并共享应用的数据库表结构,迁移通常和Laravel 的 schema 构建器结对从而可以很容易地构建应用的数据库表结构.如果你曾经告知小组成员需要手动添 ...

  2. execute() 和 sumbit() 的区别

    execute()内部实现 1.首次通过workCountof()获知当前线程池中的线程数, 如果小于corePoolSize, 就通过addWorker()创建线程并执行该任务: 否则,将该任务放入 ...

  3. TCP Nagle算法&&延迟确认机制

    TCP Nagle算法&&延迟确认机制 收藏 秋风醉了 发表于 3年前 阅读 1367 收藏 0 点赞 0 评论 0 [腾讯云]买域名送云解析+SSL证书+建站!>>> ...

  4. iOS.Animation.CAMediaTiming

    CAMediaTiming Protocol CALayre 和 CAAnimation 实现了CAMediaTiming 接口. CAMediaTiming 定义了8个属性. speed属性: Co ...

  5. qt小程序

    hello: #include <QApplication> #include <QLabel> int main(int argc, char *argv[]) { QApp ...

  6. Python之路(第十五篇)sys模块、json模块、pickle模块、shelve模块

    一.sys模块 1.sys.argv 命令行参数List,第一个元素是程序本身路径 2.sys.exit(n) 退出程序,正常退出时exit(0) 3.sys.version . sys.maxint ...

  7. 虚函数与bind 实现设计模式的练习

    相同模式使用虚函数与bind function进行实现对比 #include "stdafx.h" #include <iostream> #include <f ...

  8. Minimum Window Substring LT76

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  9. 860. Lemonade Change

    class Solution { public: bool lemonadeChange(vector<int>& bills) { , ten = ; for (int i : ...

  10. 2018.12.15 spoj Substrings(后缀自动机)

    传送门 后缀自动机基础题. 求长度为iii的子串出现次数的最大值. 对原串建出samsamsam,然后用sizsizsiz更新每个maxlenmaxlenmaxlen的答案. 然后由于后缀链接将其转化 ...