Qt Compile For Mac



Requirements

  1. Qt Compile For Mac High Sierra
  2. Qt Compile For Mac On Windows
  3. Qt Mac Address
  4. Qt Compile For Mac On Linux

These are building instructions for building Qt for Android on Linux or Mac OS X. For cross-compiling on Windows, this is currently possible under cmd.exe. For general information about Qt 5 for Android, please visit the wiki for that. Qt Designer produces.ui files. This is a special XML-based format that stores your widgets as a tree. You can either load these files at runtime, or have them translated to a programming language such as C or Python. Qt Designer normally ships as a part of Qt Creator. This is Qt's official editor and lets you do a. Installing Xcode provides the C compiler that is used by Qt Creator. To identify the correct version of Xcode to install, you need to know which OS you are running. Go to the menu - 'About This Mac' and read the macOS version number.

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:

Or by downloading and installing Xcode.

Compiler Versions

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 Reference Configuration section of the supported platforms page.

QDoc Dependencies

Since version 5.11, QDoc uses Clang to parse C++ code. If you wish to build QDoc manually, refer to Installing Clang for QDoc for specific build requirements.

Steps for Building

The following instructions describe how to build Qt from the source package. You can download the Qt 5 sources from the Downloads page. For more information, visit the Getting Started with Qt page.

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

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 ($HOME/Library/Application Support/Qt/qtlicenses.ini file).

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 $HOME/.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.

Step 2: Unpack the Archive

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:

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 option.

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 option.

Qt can also be configured to be built with debugging symbols. This process is described in detail in the Debugging Techniques document.

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

To create the library and compile all the examples and tools, type:

If -prefix is outside the build directory, you need to install the library, examples, and tools in the appropriate place. To do this, type:

Qt Compile For Mac High Sierra

This command requires that you have administrator access on your machine.

Note: 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.

This is done like this:

In .profile (if your shell is bash), add the following lines:

In .login (in case your shell is csh or tcsh), add the following line:

If you use a different shell, please modify your environment variables accordingly.

Qt is now installed.

Step 5: Build the Qt Documentation

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

Limitations

Fink

If you have installed the Qt for X11 package from Fink, it will set the QMAKESPEC environment variable to 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.

© 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.

In this blog post we'll explore the basic steps to deploy a Qt application for macOS, including assigning an icon for the application and adding assets. It is assumed that you have Qt Creator and Qt version 5.7.1 or later installed and configured on your macOS computer. If not, this blog can be used as a reference point.

Getting Started

The first thing to understand is the structure of a macOS application. MacOS makes use of the concept of bundling. Mac applications are technically folders with .app extensions.

Qt Compile For Mac

From a normal user's standpoint from the GUI, it is a single executable entity. But from a developer or command-line savvy user’s perspective, it is a folder with the executable and required resources, including libraries, assets and icon files.

Qt Compile For Mac

Qmake, by default, automatically generates a bundle for the application without the project file explicitly stating this, but it is good practice to do so, i.e.

Mac
CONFIG += app_bundle # to remove, do CONFIG -= app_bundle

Icons

Before we compile and deploy, we should look at how to set the icon that is shown on the dock, desktop, and launch folder. Modify your project file to add the following line:

ICON = myIcon.icns

Where myIcons.icns is located within your project’s filetree. Qmake will automatically create the info.plist entry needed and copy the icon into the application’s resource folder (Contents/Resources).

Adding Additional Folders

If you have additional resource files you need to include with your application but that can't be put in a qrc resource file (QML files for example), you can append it to the QMAKE_BUNDLE_DATA section in your project file:

mySetOfExtraFiles.files= $$PWD/imagesFolder
mySetOfExtraFiles.path= Contents/Resources
QMAKE_BUNDLE_DATA += mySetOfExtraFiles

These three lines will tell qmake to copy the folder imagesFolder into the application’s Contents/Resources folder. If you need it to be in the same directory as the executable, you should put the path as Contents/MacOS.

Compiling and Deployment

The first step is to compile your code in release mode and prepare it to be distributable beyond your build directory.

Compiling from the terminal

Navigate to your code folder using the terminal, and compile it:

If you were able to compile successfully without any errors, you will now see that a <ApplicationName>.app folder exists in your build directory.

Compiling from Qt Creator

To compile in Qt Creator go to Build > Clean Project “ProjectName”. This is equivalent to typing make clean on the command line. In the lower left corner of the Qt Creator interface, there is a monitor like icon, click on it and select your project name, and “release” build. Go to Build > Build project “ProjectName” (equivalent to running make on the command line).

Compile

Deployment

To deploy an application you will be making use of macdeployqt, which is a deployment tool included with Qt Creator. It is commonly located at <QTDIR>/bin/macdeployqt. (You can also search for it using the command find / -iname macdeployqt.) Qt Creator does not have this deployment option integrated into its interface so you will need to use it through the command line. macdeployqt is useful when your application has primarily Qt libraries and no custom libraries. If you have custom libraries, you will need to manually copy them into the bundle after it is created.

Assuming you are in the build directory, if you have no QML files, run:

If you have QML files, instead use:

macdeployqt <ApplicationName>.app-qmldir=<path to QMLs>

To place the bundle into a disk image for easy distribution, add -dmg to the command. You can also zip or tar the .app folder after running macdeployqt on it.

An important note about the option -qmldir=<path>: the “path” is the absolute path to the QML source files in your project folder. This is necessary for the deployment tool to parse the QML files and include the necessary Qt libraries for those QML files. This is only applicable if you have QML files in your project.

Distributing

If all went well and no fatal errors were reported, you can now test the application by doing one of the following:

  • Run the executable within the .app folder (<ApplicationName>.app/Contents/MacOS/<Application>)
  • Run the application by navigating to the build folder in Finder and double clicking on the application
  • Run the application inside the dmg or zip archive by double clicking on it in the Finder

If the application runs and does not crash, you’re ready to pass along the zip, tar, or dmg file to other macOS machines. Once the other machines receive the archive, just drag and drop the .app folder into the Applications folder and you’re all set.

If the application does crash and you were running it from the Finder, open a terminal and manually run the executable in the application. Any error messages should output to your terminal and give you an idea of what is going wrong.

I hope you've found this information valuable. (If so, please share!) More of our Qt-related technical content is available here.

Qt Compile For Mac On Windows

References

Qt Mac Address

High

Qt Compile For Mac On Linux

Qt for MacOS - Deployment