How to use Qt Creator for software development on macOS without having to install Xcode
Justification
Qt refuses to install on macOS unless Apple's Xcode is installed beforehand.This is unfortunate because:
Apr 13, 2020 Qt Creator lies within Development Tools, more precisely IDE. This free program is an intellectual property of Qt Project Hosting. This download was scanned by our built-in antivirus and was rated as virus free. The latest version of Qt Creator is supported on. In Qt Creator, choose 'File' → 'Open File or Project.' Or press Ctrl+O (or Command+O on Mac). Navigate to the SampleProject folder and open the file SampleProject.pro. Samsung smart camera app for mac. Qt Creator will ask you a few questions about how to set up the build process for this project. For more information about Qt Creator modes, see Qt Creator Modes. Moving Between Open Files. To quickly move between currently open files, press Ctrl+Tab. To move forward in the location history, press Alt+Right (Cmd+Opt+Right on Mac OS). To move backward, press Alt+Left (Cmd+Opt+Left on Mac OS).
- Xcode is huge!
- The full IDE is a 5 GB download, and can occupy 20 GB+ of space on disk.
- Qt doesn't actually need the full IDE.
- Only Xcode's command line utilities are required for macOS application development¹.
- Developers may never actually use Xcode.
- They can program in Qt Creator, like they do in Windows and Linux.
Downloading and installing the command line utilities without Toshiba dynadock drivers mac. Xcode saves time and bandwidth,and means that valuable SSD storage space is kept for better uses.
¹ I believe the full Xcode IDE is required for developing iOS apps with Qt(i.e. apps for iPads and iPhones)but I'm not sure about this as I'm not an iOS developer.
Instructions
Summary
- Install Xcode's Command Line Tools (i.e. not Xcode itself).
- Run in Terminal:
xcode-select --install
- Install Qt using the Online Installer.
- Download links:
- Open Source: https://www.qt.io/download-open-source
- Commercial: https://www.qt.io/download
- The installer will complain that Xcode is not installed.
- Keep clicking 'OK' until the message goes away permanently (after 12 clicks).
- Remember where you installed Qt (default location is
~/Qt
).- If you used a different location then you will need to change subsequent commands accordingly.
- Make sure Qt Creator uses the correct C++ Compiler.
- Launch Qt Creator for the first time from the command line,with the location of the command line tools compilers in
${PATH}
:PATH='$(xcode-select -p)/usr/bin:${PATH}' ~/Qt/Qt Creator.app/Contents/MacOS/Qt Creator
- Go to Qt Creator > Preferences > Build & Run > Kits and select a build kit (e.g.
Desktop Qt 5.
). - Check that both the C compiler and the C++ compiler are:
clang
(notgcc
)- from the Command Line Tools (not the default compilers in
/usr/bin
)
- Close Qt Creator.
- You can launch Qt Creator the normal way in future (e.g. via Spotlight).
- If your Qt version is older than Qt 5.9.2 then you need to update some QMake files.
- Navigate to the directory
~/Qt/<version>/clang_64/mkspecs/features/mac
- Make a backup copy of the following files before replacing them with newer versions from this git commit:
- Replace
sdk.prf
with this newer version. - Replace
default_pre.prf
with this newer version. - Make this change to the file
default_post.prf
:- Find the line
cache(QMAKE_XCODE_VERSION, stash)
- Replace it with
!isEmpty(QMAKE_XCODE_VERSION): cache(QMAKE_XCODE_VERSION, stash)
- Find the line
- Replace
All done!
Step-by-step
Step 1 - Download & install Xcode's Command Line Tools
Open a Terminal (press Cmd+Space and type 'Terminal') and enter this command:
Press the Return key to execute the command.
Step 2 - Download & install Qt and Qt Creator
Packages are available for MacPorts and Homebrew,but it's usually best to get it straight from the source:
- Open Source: https://www.qt.io/download-open-source
- Commercial: https://www.qt.io/download
The Online Installer is probably the best option for most people.
Tip: when you run the Online Installer it will prompt you to log in with Qt online credentials,but open-source users can skip this step without entering anything.
At a certain point during the install the following error message will appear:
You need to install Xcode version 5.0.0.Download Xcode from https://developer.apple.com/xcode
Press 'OK' or ESC to dismiss the dialog. Microsoft train simulator 2 free download. It will come back again.Keep pressing 'OK' or ESC and the dialog will eventually go away for good!You have to dismiss the dialog a total of 12 times before you can continue.
Hint: Once Qt is installed you can delete the installer as you won't need it again.If you want to update or remove Qt you have to use the MaintenanceTool in the Qt directory. Landini trekker 85 service manual.
Step 3 - Make sure Qt Creator uses the correct C++ Compiler.
Run this command in a Terminal windows to find out where Xcode's Command Line Tools are installed:
The result will probably be
/Library/Developer/CommandLineTools
,unless Xcode is installed. Whatever the result,you need to append '/usr/bin' to get something along the lines of:Run Qt Creator once with this location stored in your
${PATH}
environment variable:Go to Qt Creator > Preferences > Build & Run > Kits and select a build kit (e.g.
Desktop Qt 5.
).Check that the C and C++ compilers are the ones from the command line tools,not the default compilers in
/usr/bin
.Also check that clang
is used for both compilers, not gcc
.Qt Creator will remember the locations of the compilers,so in future you can launch Qt Creator the normal way via Spotlight.
Step 4 - Update some QMake files (only necessary for Qt versions older than Qt 5.9.2)
The
xcrun
or xcodebuild
utilities can be used to show where Xcode's Command Line Tools are installed,but only xcrun
works when Xcode itself is not installed.Qt 5.9.2 and later
Recent Qt versions use
xcrun
already, so there's nothing left for you to do!Qt 5.9.1 and older
Older Qt versions try to use
xcodebuild
to find out where the utilities are installed.This fails with the following error message unless Xcode is installed:Project ERROR: Could not resolve SDK Path for 'macosx'Error while parsing file
<filename.pro>
. Giving up.You need to tell QMake to use
xcrun
instead.Open a Terminal and change directory to where the QMake files are stored.
Now copy and paste these new commands into the same Terminal windowto create backup copies of some files:
Press the Return key after the final command.
If that all went OK then run these commands to update the files:
You can see the changes made here if you are interested.
Reusing this material
Referencing
Qt without Xcode how-to by Peter Jonas (shoogle) / CC BY 4.0
License
This work is licensed under a Creative Commons Attribution 4.0 International License.
macOS (previously known as OS X or Mac OS X) is Apple's operating system for the Mac line of computers. It's a UNIX platform, based on the Darwin kernel, and behaves largely similar to other UNIX-like platforms. The main difference is that X11 is not used as the windowing system. Instead, macOS uses its own native windowing system that is accessible through the Cocoa API.
To download and install Qt for macOS, follow the instructions on the Getting Started with Qt page.
Supported Versions
When talking about version support on macOS, it's important to distinguish between the build environment; the platform you're building on or with, and the target platforms; the platforms you are building for. The following macOS versions are supported.
Target Platform | Architecture | Build Environment |
---|---|---|
macOS 10.13, 10.14, 10.15 | x86_64 and x86_64h | Xcode 11 (10.15 SDK) |
Build Environment
The build environment on macOS is defined entirely by the Xcode version used to build your application. Xcode contains both a toolchain (compiler, linker, and other tools), and a macOS platform-SDK (headers and libraries). Together these define how your application is built.
Note: The version of macOS that you are running Xcode on does not matter. As long as Apple ships a given Xcode version that runs on your operating system, the build environment will be defined by that Xcode version.
Xcode can be downloaded from Apple's developer website (including older versions of Xcode). Once installed, choosing an Xcode installation is done using the
xcode-select
tool.You can inspect the globally selected Xcode installation using the same tool.
The
xcrun
command can then be used to find a particular tool in the toolchain.or show the platform SDK path used when building.
Target Platforms
Building for macOS utilizes a technique called weak linking that allows you to build your application against the headers and libraries of the latest platform SDK, while still allowing your application to be deployed to macOS versions lower than the SDK version. When the binary is run on a macOS version lower than the SDK it was built with, Qt will check at runtime whether or not a platform feature is available before utilizing it.
In theory this would allow running your application on every single macOS version released, but for practical (and technical) reasons there is a lower limit to this range, known as the deployment target of your application. If the binary is launched on a macOS version below the deployment target macOS or Qt will give an error message and the application will not run.
Qt expresses the deployment target via the
QMAKE_MACOSX_DEPLOYMENT_TARGET
qmake variable, which has a default value set via the makespec for macOS. You should not need to change this default, but if needed you can increase it in your project file:Note: You should not lower the deployment target beyond the default value set by Qt. Doing so will likely lead to crashes at runtime if the binary is then deployed to a macOS version lower than what Qt expected to run on.
By always building against the latest available platform SDK, you ensure that Qt can take advantage of new features introduced in recent versions of macOS.
For more information about SDK-based development on macOS, see Apple's developer documentation.
Opting out of macOS behavior changes
One caveat to using the latest Xcode version and SDK to build your application is that macOS's system frameworks will sometimes decide whether or not to enable behavior changes based on the SDK you built your application with.
For example, when dark-mode was introduced in macOS 10.14 Mojave, macOS would only treat applications built against the 10.14 SDK as supporting dark-mode, and would leave applications built against earlier SDKs with the default light mode look. This technique allows Apple to ensure that binaries built long before the new SDK and operating system was released will still continue to run without regressions on new macOS releases.
A consequence of this is that if Qt has problems dealing with some of these macOS features (dark-mode, layer-backed views), the only way to opt out of them is building with an earlier SDK (the 10.13 SDK, available through Xcode 9). This is a last-resort solution, and should only be applied if your application has no other ways of working around the problem.
Architectures
Qt Creator Open Source Download
By default, Qt is built for x86_64. To build for x86_64h (Haswell). use the
QMAKE_APPLE_DEVICE_ARCHS
qmake
variable. This is selectable at configure time:QMAKE_APPLE_DEVICE_ARCHS
can also be specified as a space-delimited list in order to build for multiple architectures simultaneously:Additional Command-Line Options
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: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).
Vacon cxl manual. 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:Deploying Applications on macOS
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.Note: For selling applications in the macOS App Store, special rules apply. In order to pass validation, the application must verify the existence of a valid receipt before executing any code. Since this is a copy protection mechanism, steps should be taken to avoid common patterns and obfuscate the code that validates the receipt as much as possible. Thus, this cannot be automated by Qt, but requires some platform-specific code written specifically for the application itself. More information can be found in Apple's documentation.
macOS Issues
The page below covers specific issues and recommendations for creating macOS applications.
Where to Go from Here
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 Overviews - list of topics about application development
- Examples and Tutorials - code samples and tutorials
- Qt Reference Pages - a listing of C++ and QML APIs
Qt's vibrant and active community site, http://qt.io houses a wiki, a forum, and additional learning guides and presentations.
Qt Creator Mac
© 2020 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.