首先官网安装最新版本的QT,因为QT分为商业版和社区版,商业版是需要收费的,我们自然选择社区版,虽然是社区版,还是需要在官网注册,然后下载最新的安装包——Qt Creator。
在安装时,需要选择性安装插件,如果全部安装好像需要20多G,最好是默认安装,因为本人电脑已经安装了VS2017,可以使用对应的编译器。所以就勾选了vs2017 32位和64位平台的插件。
到这里,我们安装完毕。就开始第一个helloworld程序吧,为什么是helloworld,因为......
新建一个工程,【文件】-->【新建文件或项目】,然后有很多种类的工程选项,我们选什么呢?于是就扒出官方的帮助文档,文档内容如下:
You can use wizards to create following types of projects:
- Applications
- Qt Widgets Application
Use Qt Designer forms to design a Qt widget based user interface for the desktop and C++ to implement the application logic- Qt Quick Application - Empty
Create an empty Qt Quick application that uses Qt Quick 2 types.
You can build the application and deploy it to desktop, embedded, and mobile target platforms.- Qt Quick Application - Scroll, Stack, or Swipe
Create a Qt Quick application that uses Qt Quick Controls to implement a scrollable list (requires Qt 5.9 or later) or a set of pages with a stack-based or swipe-based navigation model (requires Qt 5.7 or later).- Qt Console Application
Use a single main.cpp file- Qt for Python Application - Empty or Window
Create a Qt for Python application that contains only the main code for a QApplication or create one that contains an empty window.
所以我们选择Qt Widgets Application.
创建工程后,IDE工具自动生成一些文件,其中cpp文件有main.cpp和hellowolrd.cpp(helloworld是我新建工程的工程名)。
还有一个很重要的文件helloworld.ui,这个是UI设计文件,双击它就可以用拖拽的方式设计自己想要的图形界面了。这里只做了一个简单的Lable控件,将名称修改为"helloWorld"
Ctrl+shift+B 编译
Ctrl+R 运行
看到程序运行的结果如下:
![](https://img.haomeiwen.com/i5556867/fcb9f348408bc977.png)
简书的编辑器没有自带截图的功能,其实我是很想传一些图片上来的,太不方便了,希望简书在PC端的编辑器能够增强这方面的用户体验,具体可以参考QQ或者有道笔记的截图功能。
吐槽这么多,还是贴一张图吧。
ps:简书已经停更好长时间了,这篇文章就算是再次回归吧,也巧正好凑够100篇文章。后期在简书主要是一些技术类的文章,当然偶尔也会吐糟一下。感谢各位简友一直以来的关注。谢谢大家。
网友评论