https://jingyan.baidu.com/article/cbf0e500fff94c2eaa2893c7.html
- 打开菜单,新建文件或项目->其他项目->空的Qt项目,项目名设为helloqt,项目名和目录不能为中文。
- 双击“helloqt.pro”,加入代码
SOURCES += \
main.cpp
QT += core gui widgets
- 新建c++源文件,取名mian.cpp,加入代码
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);//用来管理整个应用程序所用到的资源
QLabel *label = new QLabel("<h2><i>Hello</i>""<font color = blue>Qt</font><h2>");
label -> show();//使label可见,创建窗口部件,标签通常隐藏
return app.exec();//将应用程序的控制权传递给Qt
}
//没有对QLabel对象delete,因为如此短小的程序,
//这一点内存泄漏无关大局,程序结束这部内存可由OS重新回收
- 运行