C ++ GUI, Qt simple to use, Hello world [Reserved]

Reprinted from https://blog.csdn.net/larger5/article/details/78587076

I. Introduction

 

 Before freshman use C ++ to write some simple information management system, the interface is always black and white, very poor experience, in order to add an application UI graphical interface, you can easily use the Qt5 do, and the operation is very key, many of which are compiler to help you get the foundation of the.

Qt's official website  https://www.qt.io/

The following shows a C ++ program with a graphical interface such as UI to build a level of Hello world! At the same time, look at the use of the basic components of Qt compiler

Second, the operating

1, first open Qt (you can easily go online to download)

 

 2, after then click on the interface as follows:

 

 3, click on the first

 

 4, give the project a name

 

 5, click on Next

 

 6, you can directly click Next, you can own a name to the class

 

 7, click on the completion of

 

 8, a series of automatically generated code into the following interface

 

 

9, use the shortcut Ctrl + R, you can click the bottom left corner of the icon
① The first one is compiled to run
② The second is the debugging bug
③ The third is the compiler does not run (mostly used in some cases: properties inside Add Configuration information, click here first compiled, then click run, information will be configured to take effect)

 

 

 It gave rise to the following blank interface

 

10, only the modified code main.cpp (plus button) 

 1 #include "mainwindow.h"
 2 #include <QApplication>
 3 #include <QPushButton>
 4 int main(int argc, char *argv[])
 5 {
 6     QApplication a(argc, argv);
 7     MainWindow w;
 8 
 9     QPushButton b;
10 
11     b.setText("Hello world"); //给按钮设置内容
12     b.setParent(&w); //指定父对象,注意是取地址
13     b.move(10, 10); //移动坐标 
14 
15     w.show();
16 
17     return a.exec();
18 }

效果如下,一个简单的Qt构建就这样开始了!

三、其他

附上常用快捷键
1)帮助文件:F1 (光标在函数名字或类名上,按 F1 即可跳转到对应帮助文档,查看其详细用法)

2).h 文件和对应.cpp 文件切换:F4

3)编译并运行:Ctrl + R

4)函数声明和定义(函数调用和定义)切换:F2

5)代码注释取消注释:Ctrl + / (选中代码再按快捷键)

6)字体变大变小:Ctrl + 鼠标滚轮向上向下

7)移动代码:选中所要移动的代码 -> 按住 ctrl + shift -> 键盘方向键

8)查找替换关键字:Ctrl + F

9)快速打开代码所在目录:编辑模式下 -> 选中项目文件 -> 右击 -> 选择“显示包含的目录”,即可显示项目所在目录(此方法同样可以打开代码文件所在目录)

Guess you like

Origin www.cnblogs.com/nxopen2018/p/12188772.html