您的位置:首页 > 房产 > 家装 > 成都广告公司电话号码_免费建立个人文章网站_东莞网络推广营销_竞价系统

成都广告公司电话号码_免费建立个人文章网站_东莞网络推广营销_竞价系统

2024/10/6 4:14:42 来源:https://blog.csdn.net/m0_67635008/article/details/141197019  浏览:    关键词:成都广告公司电话号码_免费建立个人文章网站_东莞网络推广营销_竞价系统
成都广告公司电话号码_免费建立个人文章网站_东莞网络推广营销_竞价系统

一、Qt项目里面有什么?

对各个文件的解释:

Empty.pro文件

QT       += core gui   # 要引入的Qt模块,后面学习到一些内容的时候可能会修改这里
#这个文件相当于Linux里面的makefile文件。makefile其实是一个非常古老的技术了。
#qmake搭配.pro起到作用和makefile是类似的。
#Qt creator 把这个过程中编译的细节都封装好了,不需要过多的关注,只需要点击运行按钮,就直接编译运行了
greaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11 #编译选项# 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_BEFORE=0x060000    # 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 <QMainWindow>QT_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_H

main.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 version="1.0" encoding="UTF-8"?>  //xml格式的文件,和html相似。
<ui version="4.0"><class>MainWindow</class><widget class="QMainWindow" name="MainWindow"><property name="geometry"><rect><x>0</x><y>0</y><width>800</width><height>600</height></rect></property><property name="windowTitle"><string>MainWindow</string></property><widget class="QWidget" name="centralwidget"/><widget class="QMenuBar" name="menubar"><property name="geometry"><rect><x>0</x><y>0</y><width>800</width><height>26</height></rect></property></widget><widget class="QStatusBar" name="statusbar"/></widget><resources/><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;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com