❝通过qmake或QLibraryInfo类获取Qt的安装信息。 ❞
使用QMake
执行命令:
代码语言:javascript复制qmake -query
输出:
代码语言:javascript复制QT_SYSROOT:
QT_INSTALL_PREFIX:C:/Qt/Qt5.12.1/5.12.1/msvc2017
QT_INSTALL_ARCHDATA:C:/Qt/Qt5.12.1/5.12.1/msvc2017
QT_INSTALL_DATA:C:/Qt/Qt5.12.1/5.12.1/msvc2017
QT_INSTALL_DOCS:C:/Qt/Qt5.12.1/Docs/Qt-5.12.1
QT_INSTALL_HEADERS:C:/Qt/Qt5.12.1/5.12.1/msvc2017/include
QT_INSTALL_LIBS:C:/Qt/Qt5.12.1/5.12.1/msvc2017/lib
QT_INSTALL_LIBEXECS:C:/Qt/Qt5.12.1/5.12.1/msvc2017/bin
QT_INSTALL_BINS:C:/Qt/Qt5.12.1/5.12.1/msvc2017/bin
QT_INSTALL_TESTS:C:/Qt/Qt5.12.1/5.12.1/msvc2017/tests
QT_INSTALL_PLUGINS:C:/Qt/Qt5.12.1/5.12.1/msvc2017/plugins
QT_INSTALL_IMPORTS:C:/Qt/Qt5.12.1/5.12.1/msvc2017/imports
QT_INSTALL_QML:C:/Qt/Qt5.12.1/5.12.1/msvc2017/qml
QT_INSTALL_TRANSLATIONS:C:/Qt/Qt5.12.1/5.12.1/msvc2017/translations
QT_INSTALL_CONFIGURATION:
QT_INSTALL_EXAMPLES:C:/Qt/Qt5.12.1/Examples/Qt-5.12.1
QT_INSTALL_DEMOS:C:/Qt/Qt5.12.1/Examples/Qt-5.12.1
QT_HOST_PREFIX:C:/Qt/Qt5.12.1/5.12.1/msvc2017
QT_HOST_DATA:C:/Qt/Qt5.12.1/5.12.1/msvc2017
QT_HOST_BINS:C:/Qt/Qt5.12.1/5.12.1/msvc2017/bin
QT_HOST_LIBS:C:/Qt/Qt5.12.1/5.12.1/msvc2017/lib
QMAKE_SPEC:win32-msvc
QMAKE_XSPEC:win32-msvc
QMAKE_VERSION:3.1
QT_VERSION:5.12.1
如果我们想得到某个信息,如QT_INSTALL_LIBS
。可以执行下列命令:
qmake -query QT_INSTALL_LIBS
输出:
代码语言:javascript复制C:/Qt/Qt5.12.1/5.12.1/msvc2017/bin
使用QLibraryInfo
另外我们还可以在程序中使用QLibraryInfo类的location函数获取到Qt的安装信息。
代码语言:javascript复制QString QLibraryInfo::location(QLibraryInfo::LibraryLocation loc)
可使用的枚举参数:
代码语言:javascript复制enum LibraryLocation
{
PrefixPath = 0,
DocumentationPath,
HeadersPath,
LibrariesPath,
LibraryExecutablesPath,
BinariesPath,
PluginsPath,
ImportsPath,
Qml2ImportsPath,
ArchDataPath,
DataPath,
TranslationsPath,
ExamplesPath,
TestsPath,
#ifdef QT_BUILD_QMAKE
SysrootPath,
SysrootifyPrefixPath,
HostBinariesPath,
HostLibrariesPath,
HostDataPath,
TargetSpecPath,
HostSpecPath,
HostPrefixPath,
LastHostPath = HostPrefixPath,
#endif
SettingsPath = 100
};