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.