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.
- Step 2: 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/Trolltech/Qt-4.7 directory, but this can be changed by using the -prefix option.
- 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/Trolltech/Qt-4.6.3 directory, but this can be changed by using the -prefix option. Cd /tmp/qt-everywhere-opensource-src-4.6.3./configure. Type./configure -help to get a list of.
Qt libraries on Mac. Ask Question Asked 5 years ago. Active 5 years ago. Viewed 724 times 0. I'm developing a c program that uses the qt libraries, specifically the QtCore library. In the makefile I need to refer to the location of the directory that contains the libraries that I use. (I do not use QtCreator). The Mac Deployment Tool. The Mac deployment tool can be found in QTDIR/bin/macdeployqt. It is designed to automate the process of creating a deployable application bundle that contains the Qt libraries as private frameworks. The mac deployment tool also deploys the Qt plugins, according to the following rules (unless -no-plugins option is used). @SGaist said in Deploy library with Qt Creator plugin on Mac: The libMyLibrary.1.dylib entry is too short, it's missing where it should be getting found. What should be added to.pro file to add path to the library? Why it works in Linux/Windows and fails on 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.
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.
Qt Libs Macos
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.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
Qt Lib For Mac Mojave
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).
Qt For Mac
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.
Qt Lib For Mac Os
Assuming you are in the build directory, if you have no QML files, run:
If you have QML files, instead use:
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.
Qt Lib For Mac Catalina
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.
Qt Lib For Mac Download
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.
References
Mac Install Qt
Qt for MacOS - Deployment