博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
QT程序HelloWorld
阅读量:2348 次
发布时间:2019-05-10

本文共 826 字,大约阅读时间需要 2 分钟。

有两种方法来写QT程序,一种是采用设计器、一种全部用代码。

一、用设计器

file->new file/project->Application->Qt Gui Application
除了主文件main.cpp和工程文件xxx.pro以外,还有ui文件xxx.ui,此文件在编译时将会转换成h文件,还有自动生成的主窗口文件mainwindow.cpp

二、用代码

file->new file/project->other project->Empty Qt Project
除了没有ui文件和mainwindow.cpp外,和用设计器一样。
出现了问题:找不到Application类,在工程文件中加上QT += widgets即可解决问题,实际上是QT4和QT5导致头文件移位而找不到。

三、工程特点

两者均会在另外一个文件夹(名称类似build-untitled-Desktop_Qt_5_1_1_GCC_32bit-Debug)下自动生成Makefile和其他需要的cpp(moc_mainwindow.cpp)和h文件(例如ui对应的h文件ui_mainwindow.h),在这个目录下执行make即可以生成可执行程序。

四、全部用代码实例程序

#include <QtGui>
#include <QApplication>
#include <QDialog>
#include <QLabel>

int main(int argc,char* argv[])

{

    QApplication app(argc,argv);

    QDialog* dd = new QDialog();
    QLabel* label = new QLabel(dd);
    label->setText("Hello World!");
    dd->show();
    return app.exec();
}

五、参考资料

1、Qt学习之路
2、Qt教程及软件.docx

转载地址:http://amxvb.baihongyu.com/

你可能感兴趣的文章
VS2010的智能提示没有了的可能原因
查看>>
Creating a Cascading Dropdown in ASP.net MVC 3 and jQuery (1)
查看>>
创建联动的 DropdownList in ASP.net MVC 3 and jQuery (2)
查看>>
HTTP触发Jenkins参数化构建(CORS Plugin)
查看>>
来自 Serenity 的 Java 8 的一些使用技巧
查看>>
ubuntu12.04--子进程 已安装 post-installation 脚本 返回了错误号 1
查看>>
系统--电脑开机一声长响
查看>>
系统--A disk read error occurred Press Ctrl+Alt+d...
查看>>
Some projects cannot be imported because they a...
查看>>
ubuntu-android--make: *** [out/host/linux-x86/o...
查看>>
原子变量与synchronized详细解释
查看>>
java.lang.OutOfMemoryError: PermGen space及其解决方法
查看>>
如何让ajaxfileupload.js支持IE9,IE10,并可以传递多个参数?
查看>>
highcharts扩展tooltip提示异步信息
查看>>
activiti--History 历史配置
查看>>
activiti--部署bpmn/bar文件详解
查看>>
win7使用Putty 连接debain
查看>>
debain 常用命令
查看>>
debain 安装amd显卡驱动
查看>>
Java Jacob 打印word文档
查看>>