Qt for macOS - 構建從源

Qt for macOS has some requirements that are given in more detail in the Qt for macOS Requirements 文檔。

The following instructions describe how to install Qt from the source package. You can download the Qt 5 sources from the 下載 頁麵。更多信息,拜訪 Qt 快速入門 頁麵。

步驟 1:安裝許可文件 (僅商業許可的 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 環境變量到各個文件路徑。

步驟 2:解包存檔

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.

Step 3: Build the Qt Library

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.

Step 4: Set the Environment Variables

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.