66 lines
1.5 KiB
Markdown
66 lines
1.5 KiB
Markdown
# Qt 使用技巧
|
|
|
|
## -platform
|
|
|
|
在直行 Qt UI 程序时通过该参数可以直行所使用的平台和 UI 系统,如
|
|
|
|
```bash
|
|
./Example -platform wayland-egl
|
|
```
|
|
|
|
## QT_DEBUG_PLUGINS
|
|
|
|
在 Shell 中
|
|
|
|
```bash
|
|
export QT_DEBUG_PLUGINS=1
|
|
```
|
|
|
|
可在直行程序时打印 PLUGINS 信息,以确认某些插件是否被正确加载。
|
|
|
|
## 添加图标
|
|
|
|
### 制作图标
|
|
|
|
先安装 ImageMagic 工具,并将其添加到系统 PATH 下方便使用。
|
|
|
|
使用以下命令将多个不同尺寸的图片打包成一个 ICO 文件。
|
|
|
|
```bash
|
|
magick.exe convert icon-16.png icon-32.png icon-256.png myappico.ico
|
|
```
|
|
|
|
### 添加图标到应用
|
|
|
|
在 Qt .pro 文件中添加以下内容,以便将图标编译到 Qt 程序中:
|
|
|
|
```qt
|
|
RC_ICONS = myappico.ico
|
|
```
|
|
|
|
However, if you already have an .rc file, for example, with the name myapp.rc, which you want to reuse, the following two steps will be required. First, put a single line of text to the myapp.rc file:
|
|
|
|
```qt
|
|
IDI_ICON1 ICON "myappico.ico"
|
|
```
|
|
|
|
Then, add this line to your myapp.pro file:
|
|
|
|
```qt
|
|
RC_FILE = myapp.rc
|
|
```
|
|
|
|
If you do not use qmake, the necessary steps are: first, create an .rc file and run the rc or windres program on the .rc file, then link your application with the resulting .res file.
|
|
|
|
更详细内容见《[Setting the Application Icon](https://doc.qt.io/qt-5/appicon.html)》。
|
|
|
|
## Windows 下程序打包
|
|
|
|
可通过
|
|
|
|
```bash
|
|
<QT Install Path>\<Tool Chain>\bin\windeployqt.exe <Exe File>
|
|
```
|
|
|
|
命令找出依赖的库。
|