NotePublic/Software/Development/Environment/Qt/Qt_使用技巧.md

118 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Qt 使用技巧
- [Qt 使用技巧](#qt-使用技巧)
- [1. -platform](#1--platform)
- [2. QT\_DEBUG\_PLUGINS](#2-qt_debug_plugins)
- [3. Linux 下 Online Install](#3-linux-下-online-install)
- [4. Online Install/MaintenanceTool 加速](#4-online-installmaintenancetool-加速)
- [5. MaintenanceTool 添加/删除组件时只显示已安装的组件 或 无法正常升级组件](#5-maintenancetool-添加删除组件时只显示已安装的组件-或-无法正常升级组件)
- [6. Linux Online Install 没有图标](#6-linux-online-install-没有图标)
## 1. -platform
在直行 Qt UI 程序时通过该参数可以直行所使用的平台和 UI 系统,如
```bash
./Example -platform wayland-egl
```
## 2. QT_DEBUG_PLUGINS
在 Shell 中
```bash
export QT_DEBUG_PLUGINS=1
```
可在执行程序时打印 PLUGINS 信息,以确认某些插件是否被正确加载。
## 3. Linux 下 Online Install
```bash
# 安装依赖软件
sudo apt install libxcb-xinerama0
# 安装下列软件包否则出现qt.qpa.plugin: Could not load the Qt platform plugin “xcb“ in ““ even though it was found.
sudo apt install libxcb-icccm4
# 如果编译测试项目提示Failed to find "GL/gl.h" in "/usr/include/libdrm".
sudo apt install libgl1-mesa-dev
# 下载在线安装工具Qt 官网变更可能导致下列连接失效,此时请到 https://download.qt.io 自行获取下载连接。
wget https://download.qt.io/official_releases/online_installers/qt-unified-linux-x64-online.run
# 执行在线安装,并指定使用清华镜像进行加速。
chmod +x ./qt-unified-linux-x64-online.run
sudo ./qt-unified-linux-x64-online.run --mirror https://mirrors.tuna.tsinghua.edu.cn/qt
```
## 4. Online Install/MaintenanceTool 加速
```bash
# For Windows
qt-unified-windows-x64-online.exe --mirror https://mirrors.tuna.tsinghua.edu.cn/qt
MaintenanceTool.exe --mirror https://mirrors.tuna.tsinghua.edu.cn/qt
# For Linux
sudo ./qt-unified-linux-x64-online.run --mirror https://mirrors.tuna.tsinghua.edu.cn/qt
sudo ./MaintenanceTool --mirror https://mirrors.tuna.tsinghua.edu.cn/qt
```
## 5. MaintenanceTool 添加/删除组件时只显示已安装的组件 或 无法正常升级组件
原因是 MaintenanceTool 本地缓存没有更新,启动 MaintenanceTool 后点击右下角的“设置”按钮,点击“本地缓存->清空缓存”。再按正常流程添加/删除/升级 组件即可。
## 6. Linux Online Install 没有图标
需要手动创建 Desktop Entry
```bash
sudo cp /opt/Qt/Tools/QtDesignStudio/share/icons/hicolor/* /usr/share/icons/hicolor
cd /usr/share/icons/hicolor
sudo gtk-update-icon-cache -f -t ./
sudo touch org.qt-project.qtcreator.desktop
sudo touch org.qt-project.qtdesignstudio.desktop
sudo touch org.qt-project.maintenancetool.desktop
```
sudo 编辑三个 .desktop 文件,内容如下:
```ini
[Desktop Entry]
Type=Application
Exec=/opt/Qt/Tools/QtCreator/bin/qtcreator %F
Name=Qt Creator
GenericName=C++ IDE for developing Qt applications
X-KDE-StartupNotify=true
Icon=QtProject-qtcreator
StartupWMClass=qtcreator
Terminal=false
Categories=Development;IDE;Qt;
MimeType= text/x-c++src;text/x-c++hdr;text/x-xsrc;application/x-designer;application/vnd.qt.qmakeprofile;application/vnd.qt.xml.resource;
```
```ini
[Desktop Entry]
Type=Application
Exec=/opt/Qt/Tools/QtDesignStudio/bin/qtdesignstudio
Name=Qt Design Studio
GenericName=Qt Design Studio
X-KDE-StartupNotify=true
Icon=QtProject-qtcreator
StartupWMClass=qtdesignstudio
Terminal=false
Categories=Development;IDE;Qt;
```
```ini
[Desktop Entry]
Type=Application
Exec=/opt/Qt/MaintenanceTool --mirror https://mirrors.tuna.tsinghua.edu.cn/qt
Name=Qt Maintenance Tool
GenericName=Qt Maintenance Tool
X-KDE-StartupNotify=true
Icon=QtProject-qtcreator
StartupWMClass=MaintenanceTool
Terminal=false
Categories=Development;Qt;
```