凡科企业网站如何建设,wordpress新用户默认,深圳哪家公司做网站,浙江中立建设网站一、Qt项目里面有什么#xff1f; 对各个文件的解释#xff1a;
Empty.pro文件
QT core gui # 要引入的Qt模块#xff0c;后面学习到一些内容的时候可能会修改这里
#这个文件相当于Linux里面的makefile文件。makefile其实是一个非常古老的技术了。
#qmake搭配.pr…一、Qt项目里面有什么 对各个文件的解释
Empty.pro文件
QT core gui # 要引入的Qt模块后面学习到一些内容的时候可能会修改这里
#这个文件相当于Linux里面的makefile文件。makefile其实是一个非常古老的技术了。
#qmake搭配.pro起到作用和makefile是类似的。
#Qt creator 把这个过程中编译的细节都封装好了不需要过多的关注只需要点击运行按钮就直接编译运行了
greaterThan(QT_MAJOR_VERSION, 4): QT widgetsCONFIG c11 #编译选项# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES QT_DISABLE_DEPRECATED_BEFORE0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES \ main.cpp \mainwindow.cppHEADERS \mainwindow.hFORMS \mainwindow.ui
#描述了当前项目中参与构建的文件都有啥编译器要编译哪些文件
#这个地方不需要手动修改Qt Creator帮我们自动维护好# Default rules for deployment.
qnx: target.path /tmp/$${TARGET}/bin
else: unix:!android: target.path /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS target# 项目的工程文件也是qmake构建时候的重要依据。mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
//要想使用这个类就需要包含对应的头文件。Qt
//的设定使用Qt中内置的类包含的头文件的名字就是和类名一致的
#include QMainWindowQT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
//创建项目时选择的父类。
class MainWindow : public QMainWindow
{Q_OBJECT //是一个Qt内置的宏宏本质上是文本替换//Qt中有一个非常核心的机制信号和槽如果某个类想使用信号和槽就需要引入//Q_OBJECT这个宏public://Qt中引入了对象树机制创建的Qt的对象就可以把这个对象给挂到对象树上往树上挂的时候//就需要指定父节点。MainWindow(QWidget *parent nullptr);~MainWindow();private:Ui::MainWindow *ui; //和form file密切相关。
};
#endif // MAINWINDOW_Hmain.cpp
#include mainwindow.h#include QApplication
//入口函数命令行参数的个数argv命令行参数。
int main(int argc, char *argv[])
{//编写一个Qt的图形化界面程序一定需要有QApplication对象QApplication a(argc, argv);//创建一个控件对象并显示出来。它的父类是QWidget都是QWidget提供的。MainWindow w;//show方法让空间显示出来w.show();//让空间隐藏//w.hide();return a.exec(); //让程序执行起来。在linux中我们学过exec*系列函数把可执行文件中的代码和数据替换到当前进程中//但在这里只是名字恰好一样
}
mainwindow.cpp
#include mainwindow.h
#include ui_mainwindow.h
//构造和析构的实现
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow) //把form file生成的界面和当mainwindow关联起来
{ui-setupUi(this);
}MainWindow::~MainWindow()
{delete ui;
}
mainwindow.ui
?xml version1.0 encodingUTF-8? //xml格式的文件和html相似。
ui version4.0classMainWindow/classwidget classQMainWindow nameMainWindowproperty namegeometryrectx0/xy0/ywidth800/widthheight600/height/rect/propertyproperty namewindowTitlestringMainWindow/string/propertywidget classQWidget namecentralwidget/widget classQMenuBar namemenubarproperty namegeometryrectx0/xy0/ywidth800/widthheight26/height/rect/property/widgetwidget classQStatusBar namestatusbar//widgetresources/connections/
/ui
二、Qt Hello World 程序
两种方式实现hello world
1、通过图形化的方式在界面上创建出一个空间显示hello world Qt Designer右上角通过树形结构显示出了当前界面上都有哪些控件。 2、通过纯代码的方式通过编写代码在界面上创建控件显示hello world
#include widget.h
#include ui_widget.h
#include QLabel
Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui-setupUi(this);QLabel* label new QLabel(this);label-setText(hello world);
}Widget::~Widget()
{delete ui;
}