第 8 節

QT environment setup

0瀏覽次數0訪問次數--跳出率--平均停留

Install QT

QT5


# debian系
sudo apt install qt5-default          # 基础开发工具(qmake、moc 等)
sudo apt install qtbase5-dev          # Qt5 核心库开发文件
sudo apt install qttools5-dev         # Qt5 工具(Qt Designer、Linguist 等)

# 红帽系

# 安装 Qt5 核心开发包
sudo dnf install qt5-qtbase-devel      # Qt5 核心库开发文件
sudo dnf install qt5-qttools-devel     # Qt5 工具(Qt Designer、Linguist 等)

# 安装常用模块(按需选择)
sudo dnf install \
  qt5-qtdeclarative-devel \           # Qt Quick
  qt5-qtsvg-devel \                   # SVG 支持
  qt5-qtwayland-devel \               # Wayland 支持
  qt5-qtwebengine-devel               # WebEngine 支持

QT6

https://www.qt.io/product/qt6


# debian系
sudo apt install qt6-base-dev qt6-tools-dev

# 红帽系
sudo dnf install qt6-qtbase-devel qt6-qttools-devel

sudo dnf install qt6-qtdeclarative-devel qt6-qtsvg-devel qt6-qtwayland-devel qt6-qt5compat-devel qt6-qtwebsockets-devel

VScode environment setup

Mainly using CMake to set up the QT5/QT6 development environment. See CMake C/C++ Compilation Environment Setup for details.

QT Designer generates .ui

The main approach is to use the following software for graphical design, then generate .ui files and convert them into .h files for use in C/C++ projects.

For example, to create a Hello World window, open QT Designer and select Create Widget.

Drag it in, and enter Hello World!

You can adjust the font size.

You can modify objectName, which is the class name called in the C++ code.

Finally, save the .ui file, usually in the form folder under the function package.

Call the .ui class and compile and run it.

First, make sure your VSCode + CMake configuration is correct.

Then in cmake .., next make install, at this point the .h file will appear in the QT_Projects/QT6/QT6_Template/build/src/QT6TEST/ directory.

Then you can reference this .h in the code.

Then you can proceed to implement your own code functionality.

#include "QT6TEST/inc/qt6_test.hpp"
#include <QApplication>
#include <QWidget>
#include "ui_mywidget.h"

int qt6_test(int argc,char **argv)
{
    QApplication app(argc, argv);

    // 创建主窗口和 UI 对象
    QWidget mainWindow;
    Ui::MyWidget ui;        // Ui 命名空间中的类名与 .ui 文件中的 class 属性一致
    ui.setupUi(&mainWindow);

    // 设置窗口标题
    mainWindow.setWindowTitle("Hello Qt6!");

    // 显示窗口
    mainWindow.show();

    return app.exec();
}

I have a pre-configured Qt6 environment here that you can clone and use.

https://github.com/tungchiahui/QT\_Projects/tree/main/QT6/QT6\_Template

音乐页