Qt Interface Mac/ja

From Free Pascal wiki
Jump to navigationJump to search

English (en) 日本語 (ja)

日本語版メニュー
メインページ - Lazarus Documentation日本語版 - 翻訳ノート - 日本語障害情報

概要

セクション2、3そして4はあなたが自らQtライブラリ、インターフェイスライブラリ、インターフェイスフレームワークを作りたいときにのみ必要となります。もし、あなたがQt4IntfFramework_PowerPC.dmg(mac_bin-qt4pas-1.xx.zipというファイルの中に含まれています)を使用してインストールしているのなら、あなたはセクション5から読み始めてデモプログラムのコンパイルを始めて下さい。

用語に関する注意:

ここで使われる"Qtライブラリ"という言葉は、セクション2で作成するQtCoreおよびQtGuiライブラリを指しています。"インターフェイスライブラリ"というのはセクション3で作成されるFreePascalとQtライブラリの間のインターフェイスライブラリであるQt4Intfライブラリを指しています。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.

もしあなたがOS Xの用語である"フレームワーク"や"appバンドル"という用語の意味を知らなければ、アップルによるオンラインドキュメントを参照してください。

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

Qt Open Source Editionを使ったQtライブラリの作成

  1. TorolltechのウェブサイトからQt Open Source Editionをダウンロードします。このファイルには「qt-mac-opensource-src-4.1.1.tar.gz」みたいな名前がついています。
  2. ファイルをダブルクリックしてStuffItでファイル名から.tar.gzの拡張子が取り除かれたフォルダに展開してください。(訳注:StuffItがインストールされていて、ダウンロードしたファイルをダブルクリックすれば自動的にそうなります)
  3. このフォルダをあなたのホームフォルダ(/Users/あなたのログインネーム)に移動してください。
  4. OS X DevSDKパッケージはインストールされていますか?このパッケージはOS X 10.3に付属のXCode Tools CDにあります。
  5. ターミナルウィンドウを開いてください。
  6. Qtのソースコードがあるフォルダに移動してください。
     cd ~/qt-mac-opensource-src-4.1.1
  7. このコマンドを打ち込んでください。
     ./configure
  8. エンターキーを叩けば、色々表示されて設定が完了し、メッセージが出力されます。
  9. 続いてこのコマンドを打ち込んでください。
     make
    こうするとソースコードがOS X DevSDKパッケージの一部であるGNUコンパイラコレクション(gcc)C++コンパイラによってコンパイルされます。このコンパイルによってQtCore.frameworkとQtGui.frameworkがQtのソースコードがあるフォルダの中のlibフォルダに作成されます。このフレームワークは我々が利用するQtライブラリを含んでいます。
    注意 コンパイルにはあなたのマシンのスピードによりますが、いくらかの時間がかかります。
  10. オプション あなたが何らかの理由でQtインターフェイスフレームワークを作成して利用したくない場合、あなたは/usr/local/Trolltechに移動して、次のコマンドを入力する事によってQtライブラリが利用できます。
     sudo make install

Qtインターフェイスライブラリの作成

mac_qt4pas-1.xx.zipにスクリプトファイルが含まれています。このファイルをダウンロードしてダブルクリックして、qt4pas-1.xxって名前のフォルダにしてください。続いてこのフォルダをホームフォルダ(/Users/あなたのログインネーム)に移動して、そこに(ターミナルからcdコマンドで)入ってください。それから、次のコマンドを打ち込んで、スクリプトを走らせてください。

 ./compile_lib_mac.sh

このスクリプトはGCC g++コンパイラを走らせてqtpas.cppをコンパイルしQt4IntfというQtインターフェイスライブラリを作成します。もし、スクリプトがQtライブラリを見つける事ができなければ、スクリプトはエラーメッセージを出力するでしょう。 -- もしあなたが違うバージョンのQtを利用しようとしていてスクリプトがエラーを出力しようとしている場合は、このエラーを修復する為にスクリプトを編集し、Qt4を設定している部分のQtのソースコードがあるフォルダの指定をあなたのQtのソースコードがあるフォルダのパスに変更してください。

Qtインターフェイスフレームワークの作成

mac_qt4pas-1.xx.zipのなかにスクリプトファイルがあります。このスクリプトファイルを実行するために次のコマンドを入力してください。

 sudo ./create_framework_mac.sh

これにより/Library/Frameworksの下にQt4Intf.frameworkフォルダが作成され、そこにQtライブラリとQtインターフェイスがコピーされます。より詳しい説明はスクリプトをご覧下さい。

sudoは/Libraryフォルダの下にファイルをコピーするために必要です。

もしスクリプトがQtライブラリを見つけられない時は、スクリプトはエラーメッセージを出力します。そのときはスクリプトを編集してQt4のソースコードがあるフォルダをあなたの環境のものにあわせて変更してください。

Lazarusを使わずFree Pascalを使ってデモプログラムをコンパイルする

いくつかのデモプログラムのソースコードはmac_demos-1.xx.zipというファイルに含まれています。このファイルをダウンロードしてダブルクリックし、demos-1.xxというフォルダを作成してください。つづいてこのフォルダをあなたのホームフォルダ(/Users/あなたのログインネーム)に移動して、そこに(ターミナルからcdコマンドを使って)入ってください。

もし必要であるならば、qt4.pasというファイルをデモフォルダの中にコピーしてください。qt4.pasというファイルはmac_qt4pas-1.xx.zipもしくはmac_bin-qt4pas-1.xx.zipの中にあります。

ひとつのデモプログラムをコンパイルするには次のコマンドを実行してください。:

 cd somedemo
 ln -s ../qt4.pas qt4.pas
 ../compile_exe_fr_mac.sh somedemo

これによりデモプログラムがFree Pascalによってコンパイルされ、適当な名前の実行ファイルが一つ作られます。

小ネタ: 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.

デモプログラムのアプリケーションバンドルの作成

OS Xダブルクリックで起動できるアプリケーションを作成するには、appバンドルを作成する必要があります。appバンドルはフォルダに.appの拡張子が追加されたもので、ユーザーから見ればファイルのように見えます。これを作成するには付属のスクリプトファイルを実行します。:

 ../create_app_mac.sh somedemo

これでsomedemo.appフォルダを作成することができ、この中にはいくつかのフォルダとファイルがあります。

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.

Finderでsomedemoアプリケーション(実行ファイルではないもの)をダブルクリックすればそれが実行されます。dockにsomedemoアプリケーションをドラッグ&ドロップすればそこから起動する事も可能です。

Compiling the Lazarus LCL for the Qt widgetset

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). Hold down the Option key when dragging so Finder copies rather than moves your Lazarus folder.

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. If necessary, copy the qt4.pas file used in section 5 above into /Users/login/Lazarus/lcl/interfaces/qt.

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. In Lazarus, choose Tools | Build Lazarus.

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.

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

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.

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

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.

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.