Qt for Windows-从源代码构建

Qt for Windows - Building from Source

Qt for Windows-从源代码构建

This page describes the process of configuring and building Qt for Windows. Before building, there are some requirements that are given in more detail in the Qt for Windows - Requirements document.

​此页面描述了为Windows配置和构建Qt的过程。在构建之前,Qt for Windows-需求文档中更详细地给出了一些要求。

You can download the Qt 5 sources from the Downloads page. For more information, visit the Getting Started with Qt page.

​可以从下载页面下载Qt 5源代码。有关更多信息,请访问Qt入门页面。

Step 1: Install the License File (Commercially Licensed Qt Only)

步骤1:安装许可证文件(仅限商业许可的Qt)

If you use Qt with a commercial license, the Qt tools look for a local license file. If you are using a binary installer or the commercial Qt Creator, your licenses are automatically fetched and stored in your local user profile (%USERPROFILE%\AppData\Roaming\Qt\qtlicenses.ini file).

如果使用带有商业许可证的Qt,Qt工具会查找本地许可证文件。如果使用的是二进制安装程序或商用Qt Creator,许可证将自动获取并存储在本地用户配置文件中(%USERPROFILE%\AppData\Roaming\Qt\qtlicenses.ini文件)。

If you do not use any binary installer or Qt Creator, you can download the respective license file from your Qt Account Web portal and save it to your user profile as %USERPROFILE%\.qt-license. If you prefer a different location or file name, you need to set the QT_LICENSE_FILE environment variable to the respective file path.

​如果不使用任何二进制安装程序或Qt Creator,可以从Qt帐户门户网站下载相应的许可证文件,并将其作为%USERPROFILE%\.qt-license保存到用户配置文件中。如果希望使用其他位置或文件名,则需要将QT_LICENSE_FILE环境变量设置为相应的文件路径。

Step 2: Unpack the Archive

第二步:打开存档

Uncompress the files into the directory you want Qt installed; e.g. C:\Qt\%VERSION%.

将文件解压缩到要安装Qt的目录中;例如C:\Qt\%VERSION%。

Note: The install path must not contain any spaces or Windows specific file system characters.

注意:安装路径不得包含任何空格或Windows特定的文件系统字符。

Step 3: Set the Environment Variables

步骤3:设置环境变量

We recommend creating a desktop link that opens a command prompt with the environment set up similar to the Command Prompt menu entries provided by Visual Studio. This is done by creating an application link passing a .cmd file setting up the environment and the command line option /k (remain open) to cmd.exe.

我们建议创建一个桌面链接,打开一个命令提示符,其环境设置类似于Visual Studio提供的命令提示符菜单项。这是通过创建一个应用程序链接来实现的,该链接将一个.cmd文件传递给cmd.exe,该文件设置了环境和命令行选项/k(保持打开状态)。

Assuming the file is called qt5vars.cmd and the Qt folder is called Qt-5 and located under C:\Qt:

假设文件名为qt5vars.cmd,Qt文件夹名为Qt-5,位于C:\Qt下:

REM Set up Microsoft Visual Studio 2017, where <arch> is amd64, x86, etc.
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvarsall.bat" <arch>
SET _ROOT=C:\Qt\Qt-5
SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
REM Uncomment the below line when using a git checkout of the source repository
REM SET PATH=%_ROOT%\qtrepotools\bin;%PATH%
SET _ROOT=

A desktop link can then be created by specifying the command %SystemRoot%\system32\cmd.exe /E:ON /V:ON /k C:\Qt\qt5vars.cmd as application and C:\Qt\Qt-5 as working directory.

然后,可以通过指定命令%SystemRoot%\system32\cmd.exe /E:ON /V:ON /k C:\Qt\qt5vars.cmd作为应用程序,C:\Qt\ Qt-5作为工作目录来创建桌面链接。

Note: Setups for MinGW are similar; they differ only in that the bin folder of the installation should be added to the path instead of calling the Visual Studio setup script. For MinGW, please make sure that no sh.exe can be found in the path, as it affects mingw32-make.


注:MinGW的设置类似;它们的不同之处仅在于,应将安装的bin文件夹添加到路径中,而不是调用Visual Studio安装脚本。对于MinGW,请确保在路径中找不到sh.exe,因为它会影响mingw32 make。

Settings required by the additional libraries (see Qt for Windows - Requirements) should also go this file below the call to the Windows SDK setup script.

​附加库所需的设置(请参阅Qt for Windows-要求)也应放在Windows SDK安装脚本调用下方的此文件中。

Step 4: Build the Qt Library

步骤4:构建Qt库

The default behavior of configure is to create an in-source build of Qt 5. If you want to install Qt 5 to a separate location, you need to specify the command line option -prefix <location>. Alternatively, the command line option -developer-build creates an in-source build for developer usage.

configure的默认行为是创建Qt 5的源代码内版本。如果想将Qt 5安装到单独的位置,需要指定命令行选项-prefix <location>。或者,命令行选项-developer-build创建了一个源代码内构建供开发人员使用。

To configure the Qt library for a debug build for your machine, type the following command in the command prompt:

要为计算机的调试版本配置Qt库,请在命令提示符下键入以下命令:

configure -debug -nomake examples -nomake tests -skip qtwebengine -opensource

The Configure Options page contains more information about the configure options.

​配置选项页面包含有关配置选项的更多信息。

To build Qt using jom, type:

​要使用jom构建Qt,请键入:

jom

If you do not have jom installed, type:

​如果没有安装jom,请键入:

nmake

For MinGW, type:

​对于MinGW,请键入:

mingw32-make

If an installation prefix was given, type jom installnmake install or mingw32-make install.

如果给出了安装前缀,请键入jom install、nmake install或mingw32 make install。

Note: If you later need to reconfigure and rebuild Qt from the same location, ensure that all traces of the previous configuration are removed by entering the build directory and typing nmake distclean before running configure again.

注意:如果以后需要从同一位置重新配置和重构建Qt,请确保在再次运行configure之前,通过进入构建目录并键入nmake distclean来删除之前配置的所有痕迹。

Parallel Builds

并行构建

jom is a replacement for nmake which makes use of all CPU cores and thus speeds up building.

jom是nmake的替代品,nmake利用所有CPU内核,从而加快了构建速度。

Step 5: Build the Qt Documentation

步骤5:构建Qt文档

For the Qt reference documentation to be available in Qt Assistant, you must build it separately:

​为了在Qt Assistant中提供Qt参考文档,必须单独构建它:

nmake docs

This will build the documentation in the build folder. If you have installed Qt in a separate location, you will also need to install the documentation:

这将在构建文件夹中构建文档。如果在单独的位置安装了Qt,还需要安装文档:

nmake install_docs

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

以下是从Qt官方网站下载源代码并使用其构建系统从源代码编译和安装Qt Charts模块的步骤: 1. 打开Qt官方网站,进入下载页面:https://www.qt.io/download-open-source/ 2. 选择“Qt Online Installer for Windows”(或适用于您的操作系统的版本)下载安装程序。 3. 运行安装程序,选择您需要的Qt版本和组件。确保勾选了“源代码”选项。 4. 安装完毕后,打开Qt Creator。 5. 点击“Tools”菜单,选择“Options”。 6. 在“Options”窗口中,选择“Kits”选项卡,并确保您选择了一个包含源代码Qt版本。 7. 点击“Apply”保存更改,然后关闭“Options”窗口。 8. 在Qt Creator中,选择“File”菜单,选择“New File or Project”。 9. 在“New Project”对话框中,选择“Other Project”类别,然后选择“Empty Qt Project”。 10. 输入项目名称和路径,点击“Next”。 11. 在“Configure Project”对话框中,选择您希望使用的Qt版本和构建工具。 12. 点击“Create Project”。 13. 在Qt Creator中,在项目导航栏中右键单击项目名称,选择“Add New”,然后选择“Qt Charts qmake Project”。 14. 在“Add Existing Files”对话框中,选择Qt Charts源代码路径下的“charts.pro”文件,然后点击“Open”。 15. 在Qt Creator中,点击“Build”菜单,选择“Build All”以编译Qt Charts模块。 16. 在Qt Creator中,点击“Build”菜单,选择“Install”以安装Qt Charts模块。 17. 完成后,您可以在Qt Creator中创建一个新的Qt Charts应用程序,并使用新编译和安装的Qt Charts模块来构建它。 注意:以上步骤仅适用于从Qt官方网站下载源代码并使用其构建系统的情况。如果您使用的是其他构建工具或从其他来源获取的Qt源代码,则步骤可能有所不同。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值