Qt for macOS

Downloading and Installing Qt

安装 Qt 有 2 种办法:

  1. 透过 Qt 安装程序 - 下载并安装 Qt
  2. 透过 Qt 源代码 .

可以下载 Qt 5 安装程序和源代码,从 下载 页面。更多信息,拜访 Qt 快速入门 页面。

从源代码构建 Qt 5

Below, you will find more information about building Qt from source.

注意: Qt 5 uses Cocoa, therefore, building for Carbon is not possible.

macOS Versions

支持平台 for the list of macOS versions supported by Qt.

Qt can be built for either x86 or x86_64. 64-bit is used by default. To select a 32-bit build, use the QMAKE_APPLE_DEVICE_ARCHS qmake variable. This is selectable at configure time:

./configure -platform macx-clang QMAKE_APPLE_DEVICE_ARCHS=i386
					

QMAKE_APPLE_DEVICE_ARCHS can also be specified as a space-delimited list in order to build for multiple architectures simultaneously:

./configure -platform macx-clang QMAKE_APPLE_DEVICE_ARCHS="i386 x86_64 x86_64h"
					

注意: Qt 5 does not support OS X on PowerPC.

注意: Static builds are not tested.

额外命令行选项

On the command-line, applications can be built using qmake and make . Optionally, qmake can generate project files for Xcode with -spec macx-xcode . If you are using the binary package, qmake generates Xcode projects by default; use -spec macx-gcc to generate makefiles. For example:

qmake -spec macx-xcode project.pro
					

Configuring with -spec macx-xcode generates an Xcode project file from project.pro. With qmake you do not have to worry about rules for Qt's preprocessors ( moc and uic ) since qmake automatically handles them and ensures that everything necessary is linked into your application.

Qt does not entirely interact with the development environment (for example plugins to set a file to "mocable" from within the Xcode user interface).

The result of the build process is an application bundle, which is a directory structure that contains the actual application executable. The application can be launched by double-clicking it in Finder, or by referring directly to its executable from the command line, for example, myApp.app/Contents/MacOS/myApp .

If you wish to have a command-line tool that does not use the GUI for example, moc , uic or ls , you can tell qmake to disable bundle creation from the CONFIG variable in the project file:

CONFIG -= app_bundle
					
					

在 macOS 部署应用程序

In general, Qt supports building on one macOS version and deploying to earlier or later macOS versions. The recommended way is to build on the latest version and deploy to an earlier macOS version.

macOS applications are typically deployed as self-contained application bundles. The application bundle contains the application executable as well as dependencies such as the Qt libraries, plugins, translations and other resources you may need. Third party libraries like Qt are normally not installed system-wide; each application provides its own copy.

A common way to distribute applications is to provide a compressed disk image (.dmg file) that the user can mount in Finder. The deployment tool, macdeployqt (available from the macOS installers), can be used to create the self-contained bundles, and optionally also create a .dmg archive. Applications can also be distributed through the Mac App Store. Qt 5 aims to stay within the app store sandbox rules. macdeployqt (bin/macdeployqt) can be used as a starting point for app store deployment.

macOS 问题

The page below covers specific issues and recommendations for creating macOS applications.

从这里开始

We invite you to explore the rest of Qt. We prepared overviews to help you decide which APIs to use and our examples demonstrate how to use our API.

Qt 振奋且活跃的社区站点, http://qt.io 包含 Wiki、论坛及其它学习指南和演示文稿。