Sign in Join
Wiki copytemporary

Qt Interface Mac

English · 日本語

(macOS only)

(Qt only)

Introduction

There are two main path you can follow to start deploying your first Qt Application for Mac:

Quick Install and Use Guide

Fastest way to get you ready to develop applications with Qt Framework (+ LCL Widgetset)

Qt4 Framework Library

First you need to download the Cocoa Mac binary package of Qt4 Framework Library from Nokia Qt download section or from a Trolltech mirror. The file you need is named something like qt-mac-opensource-4.7.4.dmg or with greater version.

Qt4 Interface Binary Bindings

Next you need to download the Interface Binary Bindings from Jan.Van.hijfte site, search for Mac: Libray Binary Intel, the file you download is named something like mac_bin-qt4pas-V2.4_Qt4.5.3.zip (don't worry about version in file name, it's indicating the lowest version required by Binaries).

Build Lazarus IDE on Qt

Lazarus 1.2/1.3 You must rebuild libQt4Pas library according to your needs (32/64bit). Build with make (from terminal):

Build from Lazarus IDE:

===Build Lazarus with qt-cocoa (qt binary distribution from nokia >= 4.7.4)=== Qt binary distribution (>=4.7.4) is 64bit (cocoa only), so we need 64bit Qt4Pas and 64bit 2.6.0 compiler

Build from terminal (short way)

Build carbon from terminal, then ide from ide

Spotted problems

Build environment

Build your first Qt Application

  1. Create a new project or use the default one that Lazarus IDE creates on first launch.
  2. Add some buttons and edit boxes to your form.
  3. Inside Project -> Project Options -> Compile Options -> Build modes click on empty macro line and choose LCLWidgetType, in relative macro value choose qt and click Ok.
  4. Now click green Run arrow and congratulate with yourself for building your first Qt Application.

Outdated Build Guide

Shebuka 17:03, 8 September 2011 (CEST) At this time, this part of guide can't be followed, because all shell script mentioned here to build Interface and Libraries are not present in Mac library sources.

Sections 2, 3, and 4 only need to be done if you are creating the Interface library, and Interface framework yourself. If you have installed the interface framework using Mac Library Binary (intel), you can start with section 5 and begin compiling the demo programs.

Notes on terminology:

These instructions generally use the term "Qt libraries" to describe the QtCore and QtGui libraries that are created in section 2. The term "interface library" is used to describe the Qt4Intf library created in section 3 that interfaces between Free Pascal and the Qt libraries. The "interface framework" is an macOS-specific folder created in section 4 that contains both the Qt libraries and interface library and can be linked against when compiling with Free Pascal.

If you're not familiar with macOS terms such as "framework" and "app bundle", refer to Apple's extensive online documentation.

Important! To run any of the scripts mentioned in sections 3-6, you may need to change its permission so that macOS will allow it to be executed:

pascal
chmod +x script_name.sh

Install the Qt Library Frameworks

Creating the Qt interface library

A script file for doing this is included with Mac library source. The downloaded file will be named like mac_qt4pas-V1.XX_Qt4.4.X.zip Download and double-click this file to create folder qt4pas-V1.XX_Qt4.4.X.zip. Move this folder to your home folder and change to it (cd). Run the script as follows:

pascal
./compile_lib_mac.sh

This script will use the GCC g++ (installation of macOS DevSDK (Xcode) is required) compiler to compile qtpas.cpp and create Qt4Intf, the Qt interface library. If the script can't find the Qt4 library frameworks, it will output an error message. The script does not check the exact Qt version, use the appropriate Qt (Qt4.3.X cannot be mixed with Qt 4.4.X)

Creating the Qt interface framework

A script file for doing this is included with mac_qt4pas-1.xx.zip. Run the script as follows:

pascal
sudo ./create_framework_mac.sh

This creates the Qt4Intf.framework folder under /Library/Frameworks. Note that sudo is required because of the need of write access in the /Library/Frameworks folder.

If the script can't find the Qt4Intf library it needs, it will output an error message. you need to compile it first (see step above)

Compiling the non-Lazarus demo programs with Free Pascal

The Pascal source for several demo programs is included in file mac_demos-1.xx.zip. Download and double-click this file to create folder demos-1.xx. Move this folder to your home folder (/Users/login) and change to it (cd).

To compile one of the demo programs:

pascal
cd somedemo
../compile_exe_fr_mac.sh somedemo

This will compile the demo program with Free Pascal, creating an executable file with the same name.

Tip: The compile script uses the compiler option -Fu..(find units in parent directory) to only need a single copy for all demoes of the rather large Qt4.pas file.

Note that Lazarus is not required to compile these demo programs.

Creating a demo program application bundle

To create a double-clickable application on macOS, you need to create an app bundle. An app bundle is a folder with an .app extension in its name that looks like a file to the user. A script file is included for doing this:

pascal
../create_app_mac.sh somedemo

This creates the somedemo.app folder, as well as several folders and files inside it.

Note that this script does not copy the executable file into the app bundle the way you normally would when you're ready to distribute an app bundle. Instead, it creates a symbolic link inside the folder that points to the executable in the somedemo folder. This approach allows you to edit and compile a program as many times as necessary without needing to copy the executable file into the app bundle folder after each compile in order to run it.

In Finder, double-click the somedemo application (not the executable file) to launch it. You can also drag and drop the somedemo application onto the dock and launch it from there.

Creating a Qt based Lazarus

Starting purely from source

Note: The X11 package does not have to be installed at all.

in a terminal do

text
svn co http://svn.freepascal.org/svn/lazarus/trunk lazarus
text
cd lazarus
make clean all LCL_PLATFORM=qt OPT="-dUSE_QT_45 -k'-framework' -k'Qt4Intf' -k'-lobjc' -k'-framework' -k'Foundation'"
text
./startlazarus

Starting from a Gtk based Lazarus

Currently Lazarus is only available for the X11-based GTK widgetset. The compiled LCL units included with Lazarus are only available for the GTK widgetset as well. The LCL units are also installed read-only, so the easiest way of compiling them for the Qt widgetset is simply to copy the LCL source to your home folder and rebuild it there. Here are the steps:

Tip: How do you get to the Lazarus folder? In Finder, choose Go | Go to Folder and enter /usr, then navigate to /usr/local/share.

Tip: You can also use Subversion (SVN) to download the Lazarus source to a folder in your home folder (or someplace where you have write access to it).

Tip: For the purposes of these examples, you really only need to copy the Lazarus "lcl" folder, but you'll need to ignore the warnings that Lazarus gives you later on.

If you only copied the "lcl" folder, you'll get a warning when you click OK. Click Ignore to ignore the warning.

Creating an LCL app that uses the Qt widgetset

and click OK.

In the meantime qt widgetset becomes more mature, so you can see Lazarus Qt IDE under macOS

Tip: You can also compile your project from a script:

pascal
qtunits=~/lazarus/lcl/units/powerpc-darwin
/usr/local/bin/fpc -dLCL -WG -Sd -gl -O1 -Cirot -k'-framework' -k'Qt4Intf' -k'-lobjc' -Fu$qtunits -Fu$qtunits/qt myproj.lpr

You can change most of the switches as needed, but be sure to leave the -k switches alone. If necessary, change the first line to the path to the LCL units you created in the previous section.


Distributing an app that uses the Qt Interface Framework

You should substitute the name of your application for "MyApp" above.

Uninstalling the Qt4 Interface and Qt4 Framework


From the Free Pascal wiki, page "Qt Interface Mac", as it stood on 2020-01-27 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.