Difference between revisions of "Qt Interface Mac"

From Free Pascal wiki
Jump to navigationJump to search
Line 26: Line 26:
 
<pre> ./compile_lib_mac.sh</pre>
 
<pre> ./compile_lib_mac.sh</pre>
  
This script will use the GCC g++ (installation of xcode required) compiler to compile qtpas.cpp and create Qt4Intf, the Qt interface library. If the script can't find the Qt libraries, it will output an error message -- this will happen if you're using a different version of the Qt source than the script expects. To fix this error, edit the script and make sure the QT4 setting specifies the path to your Qt source folder.
+
This script will use the GCC g++ (installation of OS X 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 version, use the appropriate Qt (Qt4.3.X cannot be mixed with Qt 4.4.X)
  
 
==Creating the Qt interface framework==
 
==Creating the Qt interface framework==

Revision as of 17:14, 5 November 2008

English (en) 日本語 (ja)

Introduction

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 OsX 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 OS X-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 OS X 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 OS X will allow it to be executed:

 chmod +x script_name.sh

Install the Qt Library Frameworks

2.1. Download and install Qt4 from Trolltech/Nokia: [http:/ftp://ftp.trolltech.com/qt/source/]. The file will be named something like qt-mac-opensource-4.4.X.dmg.

2.2. Several Qt frameworks will be installed in /Library/Frameworks. QtCore.framework and QtGui.framework are used.

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:

 ./compile_lib_mac.sh

This script will use the GCC g++ (installation of OS X 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 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:

 sudo ./create_framework_mac.sh

This creates the Qt4Intf.framework folder under /Library/Frameworks and copies the Qt libraries and Qt interface library to it. For more information, take a look at the script.

Note that sudo is required because of the need to copy into the /Library folder.

If the script can't find the Qt libraries it needs, it will output an error message -- you may need to edit the script to make sure the Qt4 setting specifies the path to your Qt source folder.

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

If necessary, copy the qt4.pas file into the demo folder. The qt4.pas file can be found in mac_qt4pas-1.xx.zip.

To compile one of the demo programs:

 cd somedemo
 ln -s ../qt4.pas qt4.pas
 ../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 ln command creates a symbolic link to the qt4.pas file and allows you to use a single copy of qt4.pas to compile all the demo programs. Normally with your own programs you would copy qt4.pas into your source folder and the ln command would not be necessary.

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

Creating a demo program application bundle

To create a double-clickable application on OS X, 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:

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

7.1 Checkout svn source

in a terminal do

svn co http://svn.freepascal.org/svn/lazarus/trunk lazarus

7.2 Compile lazarus using installed QtIntf framework

cd lazarus
make clean all LCL_PLATFORM=qt OPT="-dUSE_QT_4_3 -k'-framework' -k'Qt4Intf' -k'-lobjc' -k'-framework' -k'Foundation'"

7.3 run lazarus :-)

./startlazarus

Starting from a Gtk based Lazarus

Currently Lazarus on OS X 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 on OS X, 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:

7.1. Copy the "lazarus" folder from /usr/local/share to your home folder (/Users/login).

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.

7.2. Make sure the Qt widgetset is using an up-to-date version of qt4.pas. Compare the version of qt4.pas file used in section 5 above with /Users/login/Lazarus/lcl/interfaces/qt/qt4.pas. The version should be indicated in a comment at the top of qt4.pas. If necessary, install a more recent version of Lazarus.

7.3. Start Lazarus by opening an X11 window and entering:

 cd /usr/local/share/lazarus
 ./lazarus

7.4. In Lazarus, choose Environment | Environment options. On the Files tab, change the Lazarus directory from /usr/local/share/lazarus to

 /Users/login/Lazarus

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

7.5. In Lazarus, choose Tools | Configure "Build Lazarus". Set Build LCL to "Build"; set all others to "None". Also click "qt" under LCL interface.

7.6. Click the Build button.

7.7. When Free Pascal is done compiling the LCL, check that you have newly created .ppu and .o files in /Users/login/Lazarus/lcl/units/powerpc-darwin/qt.

7.8. Choose Tools | Configure, restore the LCL interface setting to "gtk", then click "Save settings".

Creating an LCL app that uses the Qt widgetset

8.1. Create a new project in Lazarus. When you started Lazarus, it created a new project -- you can use this.

8.2. In Lazarus, choose Project | Compiler Options. On the Paths tab, select "qt" under LCL Widget Type.

8.3. On the Linking tab, select Pass Options To The Linker and enter

 -framework Qt4Intf -lobjc -framework Foundation

and click OK.

8.4. Add one or more controls to your project's main form. Since the Qt widgetset is a work in progress, consult Roadmap#Widgetset_dependent_components to see which controls are working.
In the meantime qt widgetset becomes more mature, so you can see
Lazarus Qt IDE under MacOSX at http://wiki.lazarus.freepascal.org/Image:macosxqt.png

8.5. Save the project to a folder in your home folder (/Users/login).

8.6. In Lazarus, choose Run | Build to compile the project.

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

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.

8.7. Before running the app, make sure you've created an app bundle for it. You can copy the create_app_mac.sh script from section 6 to your project's folder and run it to create an app bundle for your compiled project.

8.8. To run the app, double-click the application (not the executable file) in Finder or drag it to the dock and launch it from there.

8.9. Before writing mac apps read Mac Human Interface guidelines http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/XHIGIntro/chapter_1_section_1.html

Distributing an app that uses the Qt interface framework

9.1. The create_app_mac.sh script only creates a symbolic link inside the app bundle to the actual executable file. To copy the executable file into the app bundle in order to distribute it along with the app bundle, do this:

 rm myprogram.app/contents/macos/myprogram
 cp -p myprogram myprogram.app/contents/macos/myprogram

Substitute the name of your program for "myprogram".

9.2. Consult Deploying Your Application for help with creating a distributable disk image file (.dmg extension) from your app bundle folder. Ignore the discussion of X11 and GTK since your app doesn't require them!

9.3. Be sure to install Qt4IntfFramework_PowerPC.dmg on other computers along with your app's .dmg since this installs the Qt interface framework that your app requires (as specified in the compile_exe_fr_mac.sh script or in step 8.3 above).

Important! Qt4IntfFramework_PowerPC.dmg is intended for use with open-source apps only. If your app is not distributed with an open source license, you need to obtain a commercial Qt license from Trolltech for libQtCore and libQtGui (Qt Desktop Light).

Uninstalling the Qt interface framework

If you need to remove the Qt interface framework from your computer, simply drag the Qt4Intf.framework folder from /Library/Frameworks to the trash. Finder will prompt you for your password before allowing this.

You can also drag QtIntfFramework.pkg from /Library/Receipts to the trash.

If you cannot install a Framework because OsX complains about an existing higher version Framework already present: Drag both /Library/Frameworks/Qt4Intf and /Library/Receipts/Qt4Intf to the trash.