Qt(X):Qt基础

Qt安装组件

  1. Tools的所有
  2. Qt charts
  3. Qt Data Visualization
  4. Qt Purchasing
  5. Qt Virtual Keyboard
  6. Qt WebEngine
  7. Qt Network Auth (TP)
  8. Qt Remote Objects (TP)
  9. Qt Speech(TP)

更改界面语言

Options-Enironment-Language

Qt项目说明

项目类型说明
Qt Widgets ApplicationGUI
Qt console ApplicationCmd
Qt Quick Application暂时不用
Qt Quick Controls Application暂时不用
Qt Canvas 3D暂时不看
Base Class说明
QMainwindow窗体
QWidget万能的
QDialog对话框

工程文件说明

文件说明
pro文件项目文件
widget.h窗体类的头文件
widget.cpp实现文件(所有的组件都是使用类封装)
main.cpp主函数文件
ui_widget.h在主函数外,自动生成

自己做一个简单的界面

  1. 创建工程: Application-Qt Widgets Application-基类选择Qwidget
  2. pro文件解读
    #-------------------------------------------------
    #
    # Project created by QtCreator 2022-02-05T19:45:26
    #
    #-------------------------------------------------
    
    QT       += core gui  //在工程里面加入core gui模块
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets //如果Qt库的版本大于4,就加入Widget模块
    
    TARGET = MyfirtDesktopApp//生成App的名字
    TEMPLATE = app//编译产物的类型
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which has been marked as 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 you use 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.0
    
    
    SOURCES += \    //指定工程里面有哪些APP
            main.cpp \
            widget.cpp
    
    HEADERS += \ //指定工程里面有哪些头文件
            widget.h
    
    FORMS += \ //指定工程里面有哪些UI文件
            widget.ui
    
    
  3. 主函数文件解读
#include "dialog.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);//定义创建应用程序
    Dialog w;//定义创建对话框
    w.show();//显示

    return a.exec();//应用程序运行,开始消息循环和事件处理
}

  1. widget头文件
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT//使用信号和槽必须要添加该宏

public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();

private:
    Ui::Widget *ui;//定义了一个ui指针,指向可视化界面
};

#endif // WIDGET_H
  1. widget.cpp
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);//实现了组件的各种设置,信号和槽的关联
}

Widget::~Widget()
{
    delete ui;//创建在堆区的析构需要删除
}

  1. 添加控件(注意密码隐藏找echomode)

Qstring

  1. 数字转字符串QString qs = QString::number(i)
  2. 字符串转数字toInt()
  3. 详情见[static] QString QString::number(long n, int base = 10)

qDebug

 qDebug()<<"this is kafen "<<endl;// 输出字符串

其他的说明

  1. UI的属性栏是有继承关系的,修改不同的属性会产生不一样的结果
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值