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アプリケーションをドラッグ&ドロップすればそこから起動する事も可能です。

QtウィジェットセットでLazarusLCLをコンパイルする

現行のLazarusはOS X上においてはX11をベースとしたGTKウィジェットセットでのみ動作します。Lazarusに含まれるコンパイル済みのLCLユニットもまたGTKウィジェットセットでのみ動作します。LCLユニットはOS Xの読み出し専用領域に格納されており、あなたがQtウィジェットセットで再コンパイルを行うためにはLCLのソースコードをあなたのホームディレクトリにコピーしてそこでリビルドを行う必要があります。そのためには以下のステップを参照してください。:

  1. /usr/local/share以下にあるlazarusのフォルダをあなたのホームフォルダ(/Users/あなたのログインネーム)へとコピーしてください。Finder上でOptionキーを押しながらドラッグして移動するだけで大丈夫です。
    ヒントLazarusのフォルダを探し出すには、Finderの移動メニューからフォルダへ移動を選び、/usrと入力してEnterキーを叩くだけです。ダメな時は/usr/local/share/と入力してみましょう。
    ヒントSubversion(SVN)からLazarusのソースコードをダウンロードしてそのフォルダをあなたのホームフォルダ(もしくはあなたに読み書きの権限が与えられた場所)におく事もできます。
    ヒント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.
  2. QtウィジェットセットはQt.pasの最新のバージョンを利用しているので、あなたのものが最新版であるかどうか確認してください。もし必要であれば、上のセクション5を参照し/Users/あなたのログインネーム/Lazarus/lcl/interface/qtにqt4.pasをコピーしてください。
  3. X11のウィンドウから次のコマンドを入力してLazarusを起動してください。:
    cd /usr/local/share/lazarus./lazarus
  4. Lazarusが起動したら環境→環境設定からファイルタブを開き、Lazarusディレクトリを/use/local/share/lazarusから
    /Users/あなたのログインネーム/Lazarus
    に変更してください。
    もしあなたがlclフォルダのみコピーしているのならOKをクリックしたとき警告が出ますから、無視をクリックして警告を無視してください。
  5. Lazarusのメニューからツール→Lazarusのビルド設定を選択してください。Build LCLをBuildに設定し、他はすべて"None"を選択してください。LCLインターフェイスの"qt"をクリックしてください。
  6. Lazaruaのメニューからツール→Lazarusのビルドを選択してください。
  7. Free PascalによるLCLのコンパイルが完了したら、ちゃんと新しい.ppuと.oファイルが/Users/あなたのログインネーム/Lazarus/lcl/units/powerpc-darwin(Intel Macではi686-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.