Qt requires a macOS platform SDK and corresponding toolchain to be installed on the system. You can get this by installing the Xcode command line tools:
xcode-select --install
Or by downloading and installing Xcode .
Qt for macOS is tested and compatible with several versions of GCC (GNU Compiler Collection) and Clang (as available from Xcode). For a list of tested configurations, refer to the 参考配置 章节的 支持平台 页面。
从 v5.11 起, QDoc uses Clang to parse C++ code. If you wish to build QDoc manually, refer to 为 QDoc 安装 Clang 对于特定构建要求。
The following instructions describe how to build Qt from the source package. You can download the Qt 5 sources from the 下载 页面。更多信息,拜访 Qt 快速入门 页面。
若在商业许可下使用 Qt,则 Qt 工具会查找本地许可文件。若正使用二进制安装程序或商用 Qt Creator,则会自动取出许可并存储在本地用户 Profile (配置文件) 中 (
$HOME/Library/Application Support/Qt/qtlicenses.ini
file).
若不使用任何二进制安装程序或 Qt Creator,可以下载各自的许可文件从您的
Qt 帐户
Web 门户并将其保存到您的用户 Profile (配置文件) 作为
$HOME/.qt-license
。若偏爱不同的位置或文件名,需要设置
QT_LICENSE_FILE
环境变量到各个文件路径。
Unpack the archive if you have not done so already. For example, if you have the
qt-everywhere-opensource-src-%VERSION%.tar.gz
package, type the following commands at a command line prompt:
cd /tmp gunzip qt-everywhere-opensource-src-%VERSION%.tar.gz # uncompress the archive tar xvf qt-everywhere-opensource-src-%VERSION%.tar # unpack it
This creates the directory
/tmp/qt-everywhere-opensource-src-%VERSION%
containing the files from the archive.
To configure the Qt library for your machine type, run the
./configure
script in the package directory.
By default, Qt is configured for installation in the
/usr/local/Qt-%VERSION%
directory, but this can be changed by using the
-prefix
选项。
cd /tmp/qt-everywhere-opensource-src-%VERSION% ./configure
By default, Qt is built as a framework, but you can built it as a set of dynamic libraries (dylibs) by specifying the
-no-framework
选项。
Qt can also be configured to be built with debugging symbols. This process is described in detail in the 调试技术 文档。
The 配置选项 页面包含有关 configure 选项的更多信息。
To create the library and compile all the examples and tools, type:
make
若
-prefix
is outside the build directory, you need to install the library, examples, and tools in the appropriate place. To do this, type:
sudo make -j1 install
This command requires that you have administrator access on your machine.
注意: There is a potential race condition when running make install with multiple jobs. It is best to only run one make job (-j1) for the install.
In order to use Qt, some environment variables need to be extended.
PATH - to locate qmake, moc and other Qt tools
This is done like this:
在
.profile
(if your shell is bash), add the following lines:
PATH=/usr/local/Qt-%VERSION%/bin:$PATH export PATH
在
.login
(in case your shell is csh or tcsh), add the following line:
setenv PATH /usr/local/Qt-%VERSION%/bin:$PATH
If you use a different shell, please modify your environment variables accordingly.
That's all. Qt is now installed.
If you have installed the Qt for X11 package from
Fink
, it will set the
QMAKESPEC
环境变量到
darwin-g++
. This will cause problems when you build the Qt for macOS package. To fix this, simply unset your
QMAKESPEC
or set it to
macx-g++
before you run
configure
. To get a fresh Qt distribution, run
make confclean
on the command-line.