如何在.pro文件中为TARGET使用空格和尖括号

How to use spaces and angle brackets for TARGET in .pro file

本文关键字:空格 TARGET pro 文件      更新时间:2023-10-16

我想将我的Qt应用程序命名为

测试<2>

所以我把.pro文件写为

TEMPLATE = app
TARGET = test\ \<2\>
QT = core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES +=  main.cpp

但在构建时失败:

11:14:31: Running steps for project asdf...
11:14:31: Configuration unchanged, skipping qmake step.
11:14:31: Starting: "/usr/bin/make" 
/home/erik/Qt/5.11.1/gcc_64/bin/qmake -o Makefile ../asdf/asdf.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug
WARNING: DESTDIR: Cannot access directory '../build-asdf-Desktop_Qt_5_11_1_GCC_64bit-Debug/test/ /<2'
/bin/sh: 1: cannot open 2/: No such file
/bin/sh: 1: cannot open 2/: No such file
Makefile:254: recipe for target 'test/ //<2/>' failed
make: *** [test/ //<2/>] Error 2
11:14:31: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project asdf (kit: Desktop Qt 5.11.1 GCC 64bit)
When executing step "Make"
11:14:31: Elapsed time: 00:00.

我应该如何转义TARGET中的字符?

您不应该,在qmake的情况下:您不能,因为生成的makefile将不可用。大多数操作系统都保留了这些字符,尽管具有这样名称的文件在文件系统中可能是可表示的,但它不能以典型的方式使用。有关概述,请参见例如文件名:保留字符和单词。

应用程序窗口的标题(例如,如图所示(与文件名无关。您可以使用QWidgetwindowTitle属性将它们设置为您想要的任何值。