Archive:Getting Started/Set up KDE 4 for development (zh TW): Difference between revisions
No edit summary |
No edit summary |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{TutorialBrowser_(zh_TW)| | {{TutorialBrowser_(zh_TW)| | ||
series= | series=入門| | ||
name=建立開發用的 KDE 4| | name=建立開發用的 KDE 4| | ||
Line 35: | Line 35: | ||
使用這個方法需要 '''sux''' 工具(http://fgouget.free.fr/sux/sux-readme.shtml )。'''sux''' 在大多數發行版上都有提供。當然你也可以參考下一篇的'' 在普通的 shell 裡不用 sux''文件。'''sux''' 可以讓您用一種干淨而簡潔的方式在切換到其他使用者帳號時隱式地管理 X 轉發(認證和顯示輸出)。 | 使用這個方法需要 '''sux''' 工具(http://fgouget.free.fr/sux/sux-readme.shtml )。'''sux''' 在大多數發行版上都有提供。當然你也可以參考下一篇的'' 在普通的 shell 裡不用 sux''文件。'''sux''' 可以讓您用一種干淨而簡潔的方式在切換到其他使用者帳號時隱式地管理 X 轉發(認證和顯示輸出)。 | ||
登錄時請輸入 < | 登錄時請輸入 <syntaxhighlight lang="bash">sux - kde-devel</syntaxhighlight> | ||
您的{{path|[[Getting_Started/Increased_Productivity_in_KDE4_with_Scripts/.bashrc|.bashrc]]}}腳本將幫助您正確地建立所有環境變量和其他相關配置。如果要啟動一個應用程式,只需簡單地輸入程式名稱;例如 | 您的{{path|[[Getting_Started/Increased_Productivity_in_KDE4_with_Scripts/.bashrc|.bashrc]]}}腳本將幫助您正確地建立所有環境變量和其他相關配置。如果要啟動一個應用程式,只需簡單地輸入程式名稱;例如 | ||
< | <syntaxhighlight lang="bash">kwrite</syntaxhighlight> | ||
{{Note_(zh_TW)| | {{Note_(zh_TW)| | ||
如果您遇到諸如 MIME 類型丟失的錯誤,請嘗試: | 如果您遇到諸如 MIME 類型丟失的錯誤,請嘗試: | ||
* 執行 < | * 執行 <syntaxhighlight lang="bash">unset XDG_DATA_DIRS ; kbuildsycoca4</syntaxhighlight> | ||
}} | }} | ||
Line 49: | Line 49: | ||
啟動 KDE 4 應用程式最簡單的方法是使用 <tt>su</tt> 登錄 <tt>kde-devel</tt> 使用者,然後從命令列啟動程式。請輸入以下文字登錄 | 啟動 KDE 4 應用程式最簡單的方法是使用 <tt>su</tt> 登錄 <tt>kde-devel</tt> 使用者,然後從命令列啟動程式。請輸入以下文字登錄 | ||
< | <syntaxhighlight lang="bash">su - kde-devel</syntaxhighlight> | ||
然後,輸入你的密碼 | 然後,輸入你的密碼 | ||
< | <syntaxhighlight lang="bash">export DISPLAY=:0</syntaxhighlight> | ||
{{Note_(zh_TW)|必須導入<tt>DISPLAY</tt>變數,這樣 KDE 4 程式才能在 KDE 3 桌面顯示並運行。}} | {{Note_(zh_TW)|必須導入<tt>DISPLAY</tt>變數,這樣 KDE 4 程式才能在 KDE 3 桌面顯示並運行。}} | ||
所有的環境變數和其他設定應該參照下面的連接設置正確{{path|[[Getting_Started/Increased_Productivity_in_KDE4_with_Scripts/.bashrc|.bashrc]]}}。如果想要啟動一個程式只需要簡單輸入程序的名字就可以了;例如 | 所有的環境變數和其他設定應該參照下面的連接設置正確{{path|[[Getting_Started/Increased_Productivity_in_KDE4_with_Scripts/.bashrc|.bashrc]]}}。如果想要啟動一個程式只需要簡單輸入程序的名字就可以了;例如 | ||
< | <syntaxhighlight lang="bash">kwrite</syntaxhighlight> | ||
{{Note_(zh_TW)| | {{Note_(zh_TW)| | ||
If you get errors about missing mimetypes or such, try the following: | If you get errors about missing mimetypes or such, try the following: | ||
* run < | * run <syntaxhighlight lang="bash">unset XDG_DATA_DIRS ; kbuildsycoca4</syntaxhighlight> | ||
}} | }} | ||
{{Note_(zh_TW)| | {{Note_(zh_TW)| | ||
If you get an error about not being able to connect to an X server, be sure to issue | If you get an error about not being able to connect to an X server, be sure to issue | ||
< | <syntaxhighlight lang="bash">sudo xhost +local:kde-devel</syntaxhighlight> | ||
as your regular KDE 3 user to ensure that the application can connect to your current X session. | as your regular KDE 3 user to ensure that the application can connect to your current X session. | ||
Although your X server should accept incoming TCP connections, this is often switched off as a distribution default (like with Kubuntu Feisty). When using <tt>kdm</tt> you must edit <tt>/etc/kde3/kdm/kdmrc</tt> as root and make sure it does not contain: | Although your X server should accept incoming TCP connections, this is often switched off as a distribution default (like with Kubuntu Feisty). When using <tt>kdm</tt> you must edit <tt>/etc/kde3/kdm/kdmrc</tt> as root and make sure it does not contain: | ||
< | <syntaxhighlight lang="text">ServerArgsLocal=-nolisten tcp</syntaxhighlight> | ||
Once you have fixed this, you will need to restart your X server. The <tt>xhost</tt> command should no longer return an "unable to open display" error. | Once you have fixed this, you will need to restart your X server. The <tt>xhost</tt> command should no longer return an "unable to open display" error. | ||
For convenience, you should put this in the Autostart of your regular user. To do this, create a new file in the <tt>$HOME/.kde/Autostart</tt> directory of your regular user with the following content: | For convenience, you should put this in the Autostart of your regular user. To do this, create a new file in the <tt>$HOME/.kde/Autostart</tt> directory of your regular user with the following content: | ||
< | <syntaxhighlight lang="bash"> | ||
#! /bin/sh | #! /bin/sh | ||
xhost +local:kde-devel | xhost +local:kde-devel | ||
</ | </syntaxhighlight> | ||
Make sure that the new file is executable by using <tt>chmod +x</tt> on it. | Make sure that the new file is executable by using <tt>chmod +x</tt> on it. | ||
Line 86: | Line 86: | ||
The simplest way to run a KDE 4 application with SSH in your current desktop environment is to get an X-aware shell prompt as the <tt>kde-devel</tt> user like this: | The simplest way to run a KDE 4 application with SSH in your current desktop environment is to get an X-aware shell prompt as the <tt>kde-devel</tt> user like this: | ||
< | <syntaxhighlight lang="bash">ssh -X kde-devel@localhost</syntaxhighlight> | ||
Now you can launch KDE apps as usual, for example: | Now you can launch KDE apps as usual, for example: | ||
< | <syntaxhighlight lang="bash">kwrite</syntaxhighlight> | ||
The two lines can be conveniently combined: | The two lines can be conveniently combined: | ||
< | <syntaxhighlight lang="bash">ssh -X kde-devel@localhost kwrite</syntaxhighlight> | ||
{{Note_(zh_TW)| | {{Note_(zh_TW)| | ||
Line 98: | Line 98: | ||
===== 無密碼登入 ===== | ===== 無密碼登入 ===== | ||
Before anything serious can be done using this method, a passwordless login needs to be set up. To start, run the following command as the regular desktop user: | Before anything serious can be done using this method, a passwordless login needs to be set up. To start, run the following command as the regular desktop user: | ||
< | <syntaxhighlight lang="bash">ssh-keygen -t rsa</syntaxhighlight> | ||
Hit enter three times to accept the path of {{path|~/.ssh/id_rsa}} and an empty passphrase. Now, copy the single line in {{path|~/.ssh/id_rsa.pub}} that's printed after running this command: | Hit enter three times to accept the path of {{path|~/.ssh/id_rsa}} and an empty passphrase. Now, copy the single line in {{path|~/.ssh/id_rsa.pub}} that's printed after running this command: | ||
< | <syntaxhighlight lang="bash">cat ~/.ssh/id_rsa.pub</syntaxhighlight> | ||
After that line is copied, <tt>ssh</tt> back into the <tt>kde-devel</tt> user and put the copied line in the file {{path|$HOME/.ssh/authorized_keys}}: | After that line is copied, <tt>ssh</tt> back into the <tt>kde-devel</tt> user and put the copied line in the file {{path|$HOME/.ssh/authorized_keys}}: | ||
ssh -X kde-devel@localhost $HOME/kde/bin/kwrite \ | ssh -X kde-devel@localhost $HOME/kde/bin/kwrite \ | ||
$HOME/.ssh/authorized_keys | $HOME/.ssh/authorized_keys | ||
Paste in the line, save the file, and quit KWrite. Now try running KWrite again with the same SSH command; you shouldn't have to enter a password anymore: | Paste in the line, save the file, and quit KWrite. Now try running KWrite again with the same SSH command; you shouldn't have to enter a password anymore: | ||
< | <syntaxhighlight lang="bash">ssh -X kde-devel@localhost $HOME/kde/bin/kwrite</syntaxhighlight> | ||
{{warning_(zh_TW)|Using a passwordless SSH login has certain '''security risks''', so make sure you protect your <tt>~/.ssh/id_rsa</tt> file by restricting access to it with | {{warning_(zh_TW)|Using a passwordless SSH login has certain '''security risks''', so make sure you protect your <tt>~/.ssh/id_rsa</tt> file by restricting access to it with | ||
< | <syntaxhighlight lang="bash">chmod og-xrw ~/.ssh/id_rsa</syntaxhighlight>(although the file should have these permissions when it is created)}} | ||
===== SSH 桌面檔案 ===== | ===== SSH 桌面檔案 ===== | ||
Line 115: | Line 115: | ||
You can start with an existing .desktop file as a template (like one from your desktop) or you can make one from scratch. The main idea is to prefix the command being run with this string: | You can start with an existing .desktop file as a template (like one from your desktop) or you can make one from scratch. The main idea is to prefix the command being run with this string: | ||
< | <syntaxhighlight lang="bash"> | ||
ssh -X kde-devel@localhost $HOME/kde/bin/ | ssh -X kde-devel@localhost $HOME/kde/bin/ | ||
</ | </syntaxhighlight> | ||
A simple .desktop file that runs KWrite would have the following contents: | A simple .desktop file that runs KWrite would have the following contents: | ||
< | <syntaxhighlight lang="ini"> | ||
[Desktop Entry] | [Desktop Entry] | ||
Categories=Qt;KDE;TextEditor; | Categories=Qt;KDE;TextEditor; | ||
Line 143: | Line 143: | ||
X-KDE-SubstituteUID=false | X-KDE-SubstituteUID=false | ||
X-KDE-Username= | X-KDE-Username= | ||
</ | </syntaxhighlight> | ||
{{tip_(zh_TW)|Apps launched using SSH like this don't trigger the correct launch responses, so you probably want to disable "launch feedback" for your .desktop files}} | {{tip_(zh_TW)|Apps launched using SSH like this don't trigger the correct launch responses, so you probably want to disable "launch feedback" for your .desktop files}} | ||
Line 164: | Line 164: | ||
You can now launch KDE: | You can now launch KDE: | ||
< | <syntaxhighlight lang="bash"> | ||
su - $USER | su - $USER | ||
export DISPLAY=:1 | export DISPLAY=:1 | ||
/path/to/kde4/bin/startkde-modified & | /path/to/kde4/bin/startkde-modified & | ||
</ | </syntaxhighlight> | ||
startkde-modified is a copy of the startkde-script which includes the following lines on the top: | startkde-modified is a copy of the startkde-script which includes the following lines on the top: | ||
< | <syntaxhighlight lang="bash"> | ||
export KDEDIR=`kde4-config --prefix` | export KDEDIR=`kde4-config --prefix` | ||
export LD_LIBRARY_PATH=$KDEDIR/lib | export LD_LIBRARY_PATH=$KDEDIR/lib | ||
export PATH=$KDEDIR/bin/:$PATH | export PATH=$KDEDIR/bin/:$PATH | ||
export KDEHOME=~/.kde4 | export KDEHOME=~/.kde4 | ||
</ | </syntaxhighlight> | ||
You can also use Xephyr with KDM via the Xdmcp protocol and simply a new KDE 4 session to KDM. | You can also use Xephyr with KDM via the Xdmcp protocol and simply a new KDE 4 session to KDM. | ||
Line 183: | Line 183: | ||
On Kubuntu, you can enable it by changing | On Kubuntu, you can enable it by changing | ||
< | <syntaxhighlight lang="ini"> | ||
[Xdmcp] | [Xdmcp] | ||
# Whether KDM should listen to incoming XDMCP requests. | # Whether KDM should listen to incoming XDMCP requests. | ||
# Default is true | # Default is true | ||
Enable=false | Enable=false | ||
</ | </syntaxhighlight> | ||
in {{path|/etc/kde3/kdm/kdmrc}} to | in {{path|/etc/kde3/kdm/kdmrc}} to | ||
< | <syntaxhighlight lang="ini"> | ||
[Xdmcp] | [Xdmcp] | ||
# Whether KDM should listen to incoming XDMCP requests. | # Whether KDM should listen to incoming XDMCP requests. | ||
# Default is true | # Default is true | ||
Enable=true | Enable=true | ||
</ | </syntaxhighlight> | ||
and adjust your {{path|/etc/kde3/kdm/Xaccess}} to allow your local machine access. Additionally you should make sure to set up a port blocking policy on all external interfaces for the Xdmcp port if you are doing this on a laptop or a PC in an untrusted environment. | and adjust your {{path|/etc/kde3/kdm/Xaccess}} to allow your local machine access. Additionally you should make sure to set up a port blocking policy on all external interfaces for the Xdmcp port if you are doing this on a laptop or a PC in an untrusted environment. | ||
Line 259: | Line 259: | ||
or you can can add it to your login manager. If you are using KDM (or a compatible login manager) this is done by creating a .desktop file in either {{path|`kde-config --prefix`/share/apps/kdm/sessions/}} or in {{path|/usr/share/xsessions/}}. The easiest thing to do is to copy an existing {{path|kde.desktop}} file and name it {{path|kde4.desktop}}. Open this new .desktop file in a text editor and change the <tt>Exec</tt>, <tt>TryExec</tt> and <tt>Name</tt> entries to look something like this: | or you can can add it to your login manager. If you are using KDM (or a compatible login manager) this is done by creating a .desktop file in either {{path|`kde-config --prefix`/share/apps/kdm/sessions/}} or in {{path|/usr/share/xsessions/}}. The easiest thing to do is to copy an existing {{path|kde.desktop}} file and name it {{path|kde4.desktop}}. Open this new .desktop file in a text editor and change the <tt>Exec</tt>, <tt>TryExec</tt> and <tt>Name</tt> entries to look something like this: | ||
< | <syntaxhighlight lang="ini"> | ||
Exec=$HOME/kde/bin/startkde | Exec=$HOME/kde/bin/startkde | ||
TryExec=$HOME/kde/bin/startkde | TryExec=$HOME/kde/bin/startkde | ||
Name=KDE4 | Name=KDE4 | ||
</ | </syntaxhighlight> | ||
Replace {{path|$HOME/kde}} in the example above with the prefix you are installing KDE4 into. | Replace {{path|$HOME/kde}} in the example above with the prefix you are installing KDE4 into. | ||
Line 273: | Line 273: | ||
this | this | ||
< | <syntaxhighlight lang="ini">kdehome=$HOME/.kde</syntaxhighlight> | ||
to this | to this | ||
< | <syntaxhighlight lang="ini">kdehome=$HOME/.kde4</syntaxhighlight> | ||
or paste this | or paste this | ||
< | <syntaxhighlight lang="ini"> | ||
export KDEDIR=`kde4-config --prefix` | export KDEDIR=`kde4-config --prefix` | ||
export LD_LIBRARY_PATH=$KDEDIR/lib | export LD_LIBRARY_PATH=$KDEDIR/lib | ||
export PATH=$KDEDIR/bin/:$PATH | export PATH=$KDEDIR/bin/:$PATH | ||
export KDEHOME=~/.kde4 | export KDEHOME=~/.kde4 | ||
</ | </syntaxhighlight> | ||
on top. | on top. | ||
Line 292: | Line 292: | ||
This section will explain how to use KDevelop 3.4 to develop KDE 4 applications. If you have any questions, corrections or rants about this section, please post them on the discussion page. | This section will explain how to use KDevelop 3.4 to develop KDE 4 applications. If you have any questions, corrections or rants about this section, please post them on the discussion page. | ||
==== | ==== 事前需求==== | ||
You need at least KDevelop 3.4 for this, which is still a KDE 3 application. Versions lower than 3.4 do not have Qt 4 support among other things. The KDE 4 version of KDevelop is not yet ready for serious development. You can get KDevelop at the [http://www.kdevelop.org/index.html?filename=3.4/download.html KDevelop homepage]. Make sure you install KDevelop like all other KDE 3 applications, '''not''' with your ''kde-devel'' user. | You need at least KDevelop 3.4 for this, which is still a KDE 3 application. Versions lower than 3.4 do not have Qt 4 support among other things. The KDE 4 version of KDevelop is not yet ready for serious development. You can get KDevelop at the [http://www.kdevelop.org/index.html?filename=3.4/download.html KDevelop homepage]. Make sure you install KDevelop like all other KDE 3 applications, '''not''' with your ''kde-devel'' user. | ||
Line 308: | Line 308: | ||
su - kde-devel | su - kde-devel | ||
==== | ==== 建立環境 ==== | ||
KDevelop has no native support for CMake projects. Fortunately, CMake has the ability to generate KDevelop project files itself. In order to do this, you need to pass the ''-GKDevelop3'' flag to the ''cmake'' command. This tells CMake to generate project files for KDevelop alongside the normal makefiles. The best way to do this is to modify your ''cmakekde'' function in your [[Getting_Started/Increased_Productivity_in_KDE4_with_Scripts/.bashrc|{{path|.bashrc}}]]. Just change | KDevelop has no native support for CMake projects. Fortunately, CMake has the ability to generate KDevelop project files itself. In order to do this, you need to pass the ''-GKDevelop3'' flag to the ''cmake'' command. This tells CMake to generate project files for KDevelop alongside the normal makefiles. The best way to do this is to modify your ''cmakekde'' function in your [[Getting_Started/Increased_Productivity_in_KDE4_with_Scripts/.bashrc|{{path|.bashrc}}]]. Just change | ||
< | <syntaxhighlight lang="bash"> | ||
cmake $srcFolder -DCMAKE_INSTALL_PREFIX=$KDEDIR \ | cmake $srcFolder -DCMAKE_INSTALL_PREFIX=$KDEDIR \ | ||
-DCMAKE_BUILD_TYPE=debugfull&& \ | -DCMAKE_BUILD_TYPE=debugfull&& \ | ||
make && \ | make && \ | ||
make install; | make install; | ||
</ | </syntaxhighlight> | ||
to | to | ||
< | <syntaxhighlight lang="bash"> | ||
cmake $srcFolder -GKDevelop3 -DCMAKE_INSTALL_PREFIX=$KDEDIR \ | cmake $srcFolder -GKDevelop3 -DCMAKE_INSTALL_PREFIX=$KDEDIR \ | ||
-DCMAKE_BUILD_TYPE=debugfull&& \ | -DCMAKE_BUILD_TYPE=debugfull&& \ | ||
make && \ | make && \ | ||
make install; | make install; | ||
</ | </syntaxhighlight> | ||
After you have done that, re-login so that the changes to the {{path|.bashrc}} file take effect. Then you need to rerun ''cmakekde'' in the (root) build directory of the project you want to work on with KDevelop (if you didn't use ''-GKDevelop3'' on the [[Getting_Started/Build/KDE4#Setting_up_the_environment|building step]]). For example, if you want to work on Konsole, which lives in ''kdebase'', you need to run cmakekde in the {{path|$KDE_BUILD/KDE/kdebase}} directory. This unfortunately completely rebuilds everything, but only once when you change the generator. | After you have done that, re-login so that the changes to the {{path|.bashrc}} file take effect. Then you need to rerun ''cmakekde'' in the (root) build directory of the project you want to work on with KDevelop (if you didn't use ''-GKDevelop3'' on the [[Getting_Started/Build/KDE4#Setting_up_the_environment|building step]]). For example, if you want to work on Konsole, which lives in ''kdebase'', you need to run cmakekde in the {{path|$KDE_BUILD/KDE/kdebase}} directory. This unfortunately completely rebuilds everything, but only once when you change the generator. | ||
Line 330: | Line 330: | ||
A simple way to do this is to add the following function to your {{path|.bashrc}}: | A simple way to do this is to add the following function to your {{path|.bashrc}}: | ||
< | <syntaxhighlight lang="bash"> | ||
function start3app { | function start3app { | ||
mkdir -p /tmp/$USER-kde | mkdir -p /tmp/$USER-kde | ||
Line 344: | Line 344: | ||
source $HOME/.bashrc #Reset environment variables again | source $HOME/.bashrc #Reset environment variables again | ||
} | } | ||
</ | </syntaxhighlight> | ||
The ''PATH'' and ''LD_LIBRARY_PATH'' variables are taken from the KDE 3 user, and they may be different on your system. Type < | The ''PATH'' and ''LD_LIBRARY_PATH'' variables are taken from the KDE 3 user, and they may be different on your system. Type <syntaxhighlight lang="bash">echo $PATH</syntaxhighlight> and <syntaxhighlight lang="bash">echo $LD_LIBRARY_PATH</syntaxhighlight> as normal KDE 3 user to get these values. The above function assumes that KDE 3 is installed in the {{path|/usr}} prefix, as it is the case on Debian-based systems. If your KDE 3 is installed to a different prefix, you need to change the line setting ''KDEDIR'' accordingly. Here's an example how you find out your KDE installation prefix; in this example it is /opt/kde3: | ||
< | <syntaxhighlight lang="bash"> | ||
kde-config --prefix | kde-config --prefix | ||
/opt/kde3 | /opt/kde3 | ||
</ | </syntaxhighlight> | ||
Now you should be able to start KDevelop by typing <tt>start3app kdevelop</tt>. Do that now. | Now you should be able to start KDevelop by typing <tt>start3app kdevelop</tt>. Do that now. | ||
Line 370: | Line 370: | ||
--> | --> | ||
===== | ===== 疑難排解 ===== | ||
'''Symptome:''' kdevelop says "cannot talk to klauncher". You cannot open a file. | '''Symptome:''' kdevelop says "cannot talk to klauncher". You cannot open a file. | ||
Line 492: | Line 492: | ||
Refer to the [http://docs.kde.org/development/en/kdevelop/kdevelop/ KDevelop manual] for general help using KDevelop. The following section will only deal with special cases for KDE 4. | Refer to the [http://docs.kde.org/development/en/kdevelop/kdevelop/ KDevelop manual] for general help using KDevelop. The following section will only deal with special cases for KDE 4. | ||
===== | ===== 除錯 ===== | ||
KDE apps have many symbols, which means that you need a lot of memory to get a decent loading times for debugging. To quote a GDB developer: "I would be reluctant to debug KDE on something with <1GB RAM." | KDE apps have many symbols, which means that you need a lot of memory to get a decent loading times for debugging. To quote a GDB developer: "I would be reluctant to debug KDE on something with <1GB RAM." | ||
Line 502: | Line 502: | ||
KDevelop does not yet support modifing the CMake build system. This means you can not use KDevelop to add or remove files from the project or to change any other aspect of your project's build process. | KDevelop does not yet support modifing the CMake build system. This means you can not use KDevelop to add or remove files from the project or to change any other aspect of your project's build process. | ||
You need to modify the CMake files by hand and then rerun <tt>cmakekde</tt> instead. Read the [[Development/Tutorials/ | You need to modify the CMake files by hand and then rerun <tt>cmakekde</tt> instead. Read the [[Development/Tutorials/CMake_(zh_TW)|CMake tutorial]] to learn how to do this. | ||
}} | }} | ||
Line 603: | Line 603: | ||
: Choose Project -> Properties -> C/C++ Build -> Builder Settings. Un-tag "use default build command", set "cmake" instead. Choose Project -> Properties -> C/C++ Build -> Behavior. Replace "all" by ".". | : Choose Project -> Properties -> C/C++ Build -> Builder Settings. Un-tag "use default build command", set "cmake" instead. Choose Project -> Properties -> C/C++ Build -> Behavior. Replace "all" by ".". | ||
==== | ==== 另見 ==== | ||
* http://javathreads.de/2008/07/subversion-unter-eclipse-ganymede-konfigurieren/ | * http://javathreads.de/2008/07/subversion-unter-eclipse-ganymede-konfigurieren/ | ||
* http://nienhueser.de/blog/?p=19 | * http://nienhueser.de/blog/?p=19 | ||
=== | === Qt Creator === | ||
這裡說明如何使用 Qt Creator 開發 KDE 4 應用程式。It has been tested with QtCreator 1.2.80 and SUSE Linux 11.1 but should work same or similar with every combination.我們使用來自 kdepim 模塊的[http://userbase.kde.org/ktimetracker ktimetracker]作為 KDE 應用程式的範例。 | |||
==== 載入現有專案 ==== | |||
我們使用 ktimetracker 作為範例專案。 | |||
* 匯入 CMakeLists.txt 檔案 | |||
* | |||
File -> Open -> kdepim/CMakeLists.txt. | File -> Open -> kdepim/CMakeLists.txt. | ||
* | * 配置 Qt Creator 只建構 ktimetracker | ||
Projects -> ktimetracker -> build settings -> Add a configuration ktimetracker. | Projects -> ktimetracker -> build settings -> Add a configuration ktimetracker. | ||
As build directory choose /home/youruser/kdepim/ktimetracker. As arguments for cmake use ... | As build directory choose /home/youruser/kdepim/ktimetracker. As arguments for cmake use ... | ||
==== | ==== 開始 KDE 專案 ==== | ||
想要開始一個新的專案你需要告訴 Qt Creator 建構時使用 KDE 程式庫。因此,選擇 File -> New... 並創建您的專案。在這裡我們稱為''yourproject''。為了能夠使用 KDE 程式庫,在你的家目錄,cd 進入''yourproject''並修改 ''yourproject.pro''。加上 | |||
LIBS += -lkdeui | LIBS += -lkdeui | ||
[[Category:KDE4]] | [[Category:KDE4]] |
Revision as of 13:45, 18 July 2012
Template:TutorialBrowser (zh TW)
啟動 KDE 4 應用程式和工作階段
當您開始 KDE 4 的開發時,通常您有三個選擇:
- 您可以在目前桌面環境中以獨立於其他程式的方式執行 KDE 4 應用程式。
- 您可以在目前桌面環境中嵌入一個 KDE 4 工作階段。
- 您可以在您的機器上執行 KDE 4 作為唯一的桌面環境。
隨後的章節會描述這三種選擇。
啟動 KDE 4 應用程式
在普通的 shell 裡使用 sux
使用這個方法需要 sux 工具(http://fgouget.free.fr/sux/sux-readme.shtml )。sux 在大多數發行版上都有提供。當然你也可以參考下一篇的 在普通的 shell 裡不用 sux文件。sux 可以讓您用一種干淨而簡潔的方式在切換到其他使用者帳號時隱式地管理 X 轉發(認證和顯示輸出)。
登錄時請輸入
sux - kde-devel
您的.bashrc腳本將幫助您正確地建立所有環境變量和其他相關配置。如果要啟動一個應用程式,只需簡單地輸入程式名稱;例如
kwrite
在普通的 shell 裡不用 sux
啟動 KDE 4 應用程式最簡單的方法是使用 su 登錄 kde-devel 使用者,然後從命令列啟動程式。請輸入以下文字登錄
su - kde-devel
然後,輸入你的密碼
export DISPLAY=:0
所有的環境變數和其他設定應該參照下面的連接設置正確.bashrc。如果想要啟動一個程式只需要簡單輸入程序的名字就可以了;例如
kwrite
Template:Note (zh TW) Template:Note (zh TW)
使用 SSH
The simplest way to run a KDE 4 application with SSH in your current desktop environment is to get an X-aware shell prompt as the kde-devel user like this:
ssh -X kde-devel@localhost
Now you can launch KDE apps as usual, for example:
kwrite
The two lines can be conveniently combined:
ssh -X kde-devel@localhost kwrite
無密碼登入
Before anything serious can be done using this method, a passwordless login needs to be set up. To start, run the following command as the regular desktop user:
ssh-keygen -t rsa
Hit enter three times to accept the path of ~/.ssh/id_rsa and an empty passphrase. Now, copy the single line in ~/.ssh/id_rsa.pub that's printed after running this command:
cat ~/.ssh/id_rsa.pub
After that line is copied, ssh back into the kde-devel user and put the copied line in the file $HOME/.ssh/authorized_keys:
ssh -X kde-devel@localhost $HOME/kde/bin/kwrite \ $HOME/.ssh/authorized_keys
Paste in the line, save the file, and quit KWrite. Now try running KWrite again with the same SSH command; you shouldn't have to enter a password anymore:
ssh -X kde-devel@localhost $HOME/kde/bin/kwrite
SSH 桌面檔案
If you want to be able to launch apps more easily than running them with an SSH command from the command line, one way is to create .desktop files that ssh into the other account. Template:Note (zh TW)
You can start with an existing .desktop file as a template (like one from your desktop) or you can make one from scratch. The main idea is to prefix the command being run with this string:
ssh -X kde-devel@localhost $HOME/kde/bin/
A simple .desktop file that runs KWrite would have the following contents:
[Desktop Entry]
Categories=Qt;KDE;TextEditor;
Comment=
DocPath=kwrite/index.html
Encoding=UTF-8
Exec=ssh -X kde-devel@localhost /home/kde-devel/kde/bin/kwrite %U
GenericName=Text Editor
Icon=kwrite
InitialPreference=8
MimeType=text/plain
Name=KWrite (kde-devel)
Path=
StartupNotify=false
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-StartupType=Multi
X-DCOP-ServiceType=non
X-KDE-StartupNotify=true
X-KDE-SubstituteUID=false
X-KDE-Username=
啟動 KDE 4 工作階段
嵌套 KDE 4 工作階段
Instead of using a full-blown new virtual X for developing software you can use Xephyr to embed your KDE 4 session into your working KDE 3 or other X11 environment.
You can also do this with xnest, but as xnest cannot handle extensions like Render many people prefer Xephyr.
If you want to get a minimal KDE session up and running, just launch Xephyr (available in Kubuntu as xserver-xephyr; Gentoo users compile x11-base/xorg-server with USE="kdrive"):
Xephyr :1 -extension GLX &
You can now launch KDE:
su - $USER
export DISPLAY=:1
/path/to/kde4/bin/startkde-modified &
startkde-modified is a copy of the startkde-script which includes the following lines on the top:
export KDEDIR=`kde4-config --prefix`
export LD_LIBRARY_PATH=$KDEDIR/lib
export PATH=$KDEDIR/bin/:$PATH
export KDEHOME=~/.kde4
You can also use Xephyr with KDM via the Xdmcp protocol and simply a new KDE 4 session to KDM.
On Kubuntu, you can enable it by changing
[Xdmcp]
# Whether KDM should listen to incoming XDMCP requests.
# Default is true
Enable=false
in /etc/kde3/kdm/kdmrc to
[Xdmcp]
# Whether KDM should listen to incoming XDMCP requests.
# Default is true
Enable=true
and adjust your /etc/kde3/kdm/Xaccess to allow your local machine access. Additionally you should make sure to set up a port blocking policy on all external interfaces for the Xdmcp port if you are doing this on a laptop or a PC in an untrusted environment.
If you are done, simply launch Xephyr:
Xephyr -query localhost :1 -host-cursor -screen 1024x768&
where -host-cursor tries to reuse the host's cursor and -screen sets the screen dimensions.
Note: If you get lots of refused connection errors, you might want to use the -ac option of Xephyr. For example:
Xephyr -ac :1&
Another option to try if you get lots of refused connection errors is you may need to grant assess to your kde-devel user to your X server. As root or using sudo execute:
xhost +local:kde-devel
If you do not have Xephyr, you can also use Xnest:
Xnest -ac :1& export DISPLAY=:1
cleanup confusing sections and fix sections which contain a todo
Sping 00:25, 9 April 2007 (CEST)
I use this for my start script nested_kde4.sh:
#! /bin/bash NESTED_KDE_DISPLAY_BACKUP=$DISPLAY export DISPLAY=:0 Xephyr :1 -screen 1024x768 & export DISPLAY=:1 $HOME/kde/bin/startkde-modified & export DISPLAY=${NESTED_KDE_DISPLAY_BACKUP}
If you run into
"Call to lnusertemp failed (temporary directories full?). Check your installation."
try this:
mkdir /var/tmp/kde-devel-kde4
The above code assumes you work with user kde-devel. Template:Note (zh TW)
唯一的 KDE 4 工作階段
To run a full KDE 4 desktop environment session, you can either start it from the command line as you normally would, with something like this:
X :1 & export DISPLAY=:1 startkde
or you can can add it to your login manager. If you are using KDM (or a compatible login manager) this is done by creating a .desktop file in either `kde-config --prefix`/share/apps/kdm/sessions/ or in /usr/share/xsessions/. The easiest thing to do is to copy an existing kde.desktop file and name it kde4.desktop. Open this new .desktop file in a text editor and change the Exec, TryExec and Name entries to look something like this:
Exec=$HOME/kde/bin/startkde
TryExec=$HOME/kde/bin/startkde
Name=KDE4
Replace $HOME/kde in the example above with the prefix you are installing KDE4 into.
After restarting the login manager (Alt+e in KDM) this new entry should appear in the sessions menu.
You might have to edit your startkde scripts, ie: change
this
kdehome=$HOME/.kde
to this
kdehome=$HOME/.kde4
or paste this
export KDEDIR=`kde4-config --prefix`
export LD_LIBRARY_PATH=$KDEDIR/lib
export PATH=$KDEDIR/bin/:$PATH
export KDEHOME=~/.kde4
on top.
開發任務
KDevelop
This section will explain how to use KDevelop 3.4 to develop KDE 4 applications. If you have any questions, corrections or rants about this section, please post them on the discussion page.
事前需求
You need at least KDevelop 3.4 for this, which is still a KDE 3 application. Versions lower than 3.4 do not have Qt 4 support among other things. The KDE 4 version of KDevelop is not yet ready for serious development. You can get KDevelop at the KDevelop homepage. Make sure you install KDevelop like all other KDE 3 applications, not with your kde-devel user.
You also need the lastest GDB version, which is currently 6.6.0. Note that the GDB version which is shipped with openSuse 10.3 is broken, it constantly crashes when examining variables (which KDevelop does automatically). Use the GDB version from this repository instead.
You need to have the kdelibs API documentation locally, which is described in the build instructions.
You also need ctags, htdig, htmerge and htsearch. valgrind and callgrind can also be useful.
Be sure you followed the steps in the KDE 4 build instructions and have a working KDE 4 environment. Make sure simple KDE 4 applications like Konsole or KWrite can be started from the command line of the kde-devel user without problems.
The following steps are all done with the kde-devel user. You need to login as that user by typing
su - kde-devel
建立環境
KDevelop has no native support for CMake projects. Fortunately, CMake has the ability to generate KDevelop project files itself. In order to do this, you need to pass the -GKDevelop3 flag to the cmake command. This tells CMake to generate project files for KDevelop alongside the normal makefiles. The best way to do this is to modify your cmakekde function in your .bashrc. Just change
cmake $srcFolder -DCMAKE_INSTALL_PREFIX=$KDEDIR \
-DCMAKE_BUILD_TYPE=debugfull&& \
make && \
make install;
to
cmake $srcFolder -GKDevelop3 -DCMAKE_INSTALL_PREFIX=$KDEDIR \
-DCMAKE_BUILD_TYPE=debugfull&& \
make && \
make install;
After you have done that, re-login so that the changes to the .bashrc file take effect. Then you need to rerun cmakekde in the (root) build directory of the project you want to work on with KDevelop (if you didn't use -GKDevelop3 on the building step). For example, if you want to work on Konsole, which lives in kdebase, you need to run cmakekde in the $KDE_BUILD/KDE/kdebase directory. This unfortunately completely rebuilds everything, but only once when you change the generator.
Since all environment variables of the kde-devel user are KDE 4 specific, these need to be set back to match your KDE 3 environment before starting KDevelop. A simple way to do this is to add the following function to your .bashrc:
function start3app {
mkdir -p /tmp/$USER-kde
export PATH=/opt/kde3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games
export LD_LIBRARY_PATH=
export KDETMP=/tmp/$USER-kde
export KDEVARTMP=/var/tmp/$USER-kde
export KDEHOME=$HOME/.kde
export KDEDIR=/usr
export KDEDIRS=$KDEDIR
export DISPLAY=:0
eval "$@"
source $HOME/.bashrc #Reset environment variables again
}
The PATH and LD_LIBRARY_PATH variables are taken from the KDE 3 user, and they may be different on your system. Type
echo $PATH
and
echo $LD_LIBRARY_PATH
as normal KDE 3 user to get these values. The above function assumes that KDE 3 is installed in the /usr prefix, as it is the case on Debian-based systems. If your KDE 3 is installed to a different prefix, you need to change the line setting KDEDIR accordingly. Here's an example how you find out your KDE installation prefix; in this example it is /opt/kde3:
kde-config --prefix
/opt/kde3
Now you should be able to start KDevelop by typing start3app kdevelop. Do that now.
疑難排解
Symptome: kdevelop says "cannot talk to klauncher". You cannot open a file.
Solution: add your KDE library path to LD_LIBRARY_PATH, e.g.:
export LD_LIBRARY_PATH=/opt/kde3/lib
建立 KDevelop
Now that KDevelop has started, you need to adjust a few settings. Go to Settings->Configure KDevelop...->Documentation for this. Remove all entries that are not relevant to KDE 4 coding.
Optionally, you can add the kdelibs API documentation. You must create it beforehand. Then add the documentation by clicking Add.... In this dialog, use the following settings:
- Type: Doxygen Documentation Collection (needs to be set first)
- Location: $KDE_SRC/KDE/kdelibs/kdelibs-apidocs/index.html
Now add the Qt API documentation, which also must be created beforehand, using the following settings:
- Type: Qt Documentation Collection (needs to be set first)
- Location: $HOME/qt-copy/doc/html/qt.dcf
After you have added kdelibs and Qt API documentation, make sure all checkboxes (TOC,Index and Search) are enabled. Then, go to the Full Text Search tab and make sure the paths to the htdig, htmerge and htsearch executables are correct. You can then close the settings dialog.
Now it is time to open the project you want to work on by clicking Project->Open Project.... The project files are located in the build directory. For example, if you want to work on Konsole, you need to open $KDE_BUILD/KDE/kdebase/apps/konsole/konsole.kdevelop. You now need to adjust a few project-specific settings in Project->Project Options. You need to do this every time you start to work on a different project.
- C++ Support->Code Completion
- Here you need to add code completion databases for Qt and kdelibs, and more if you like, for example you might need a database for kdepimlibs when working on kdepim.
- For kdelibs, click the Add... button and choose KDevelop Custom Directory PCS Importer, then add your KDE include directory ($HOME/kde/include) to the list and proceed. You can use the file selection dialog and the Add button to add it.
- Now, add the database for Qt 4 by selecting KDevelop Qt4 PCS Importer this time. You need to select the Qt 4 include directory, which is $HOME/qt-copy/include.
- C++ Support->Qt Options
- Check Enable Qt options and choose Qt4 as your version. Set the QMake Binary path to $HOME/qt-copy/bin/qmake. Then choose Qt 4 style as Qt include syntax. Use $HOME/qt-copy/bin/designer as Designer Binary. Make sure to use the Change Plugin Paths dialog to add the plugin directory from KDE so you see the KDE widgets when designer is started. To do this add $HOME/kde/lib/kde4/plugins to the lineedit and then click the Add button.
- Run Options
- Make sure you use the correct binary as Executable. For example, if you want to run Konsole, this is $KDE_BUILD/KDE/kdebase/apps/konsole/src/konsole. You should add --nofork to the Debug Arguments or debugging some applications like KMail will not work at all.
- Because the start3app functions changes some environment variables, you need to change them back here so the KDE 4 applications can be run without problems from within KDevelop.
- For some applications, like Konsole, this is not strictly necessary, but others like KMail will crash if you do not change this.
- Simply click the Add / Copy button to add new environment variables. You will need the following, which are the same as in your .bashrc:
Name Value KDEHOME $HOME/.kde4 PATH $KDEDIR/bin:$QTDIR/bin:/usr/local/bin:$PATH LD_LIBRARY_PATH $KDEDIR/lib:$QTDIR/lib:$LD_LIBRARY_PATH KDETMP /tmp/$USER-kde4 KDEVARTMP /var/tmp/$USER-kde4 KDEDIR $HOME/kde KDEDIRS $KDEDIR LD_BIND_NOW 42
- Build Options->Build
- Make sure the correct build directory is selected. Again, for Konsole, this would be $KDE_BUILD/KDE/kdebase/apps/konsole.
- Build Options->Make
- You might want to check Abort on first error. You also might want to add VERBOSE= or VERBOSE=1 to Additional make options to control the level of verbosity for the build process.
- If you have more than one processor or if you have access to an icecream cluster, you might want to check the Run multiple jobs option and set the Number of simultaneous jobs to the number of available processors. This increases the compile speed. It is the same as the -j option for make.
- Formatting
- You should set all options here to match the coding style of the project you are working on.
- CTags->General
- You need to correctly set the Path to ctags binary, which is /usr/bin/ctags on Debian-based systems.
- You probably want to enable the When more than one hit, go directly to the first option.
Now you have finished adjusting your project-specific settings. Now you should remove some plugins you do not need, in Settings->Configure Plugins.... I for example disable the following plugins:
Abbreviation Expansion, Code Snippets, Doxygen Support, Embedded Konsole, File Tree, Final Packaging Support, "Open with" Menu Addon, QuickOpen, Regular Expression Tester, Scripting, Security Checker, Shell Filtering and Insertion, Text Structure and Tools Menu Addition.
You should at least disable the bold ones.
Now, open any source file if none is open already. This will enable the Settings->Configure Editor... entry, where you need to set the tab options to match the tab style used by the project you are working on. The important settings are:
- Appearance->Borders->Show line numbers: Should be checked.
- Appearance->Borders->Show icon border: Should be checked.
- Editing->Tabulators
- Editing->Static Word Wrap->Show marker: Should be checked
- Indentation->Automatic Indentation->Indentation mode: Should be C Style
- Indentation in general
In the mainwindow, click the CTags tab on the bottom tabbar, then click the Regenerate button to create a CTags database for easier source code navigation.
Now you have completed all essential configuration, congratulations!
使用 KDevelop
Refer to the KDevelop manual for general help using KDevelop. The following section will only deal with special cases for KDE 4.
除錯
KDE apps have many symbols, which means that you need a lot of memory to get a decent loading times for debugging. To quote a GDB developer: "I would be reluctant to debug KDE on something with <1GB RAM." If the stepping function of the debugger is slow for you, try the following tips:
- Hide local variables. The Locals part of the variable tab on the left causes a big slowdown when stepping if you have many local variables. Simple collapse the Locals part of the tree, the local variables are then not updated every step. You can still examine variables by using the Evaluate expression function.
- Use the patch at http://bugs.kde.org/show_bug.cgi?id=143977. It prevents the update of the framestack widget at each step, speeding up stepping considerably. The patch introduces some minor glitches, which is why it is not yet commited.
Eclipse
This describes how to use Eclipse to develop KDE 4 applications. It has been tested with Eclipse Ganymed and SUSE Linux 11.1 but should work same or similar with every combination. As an example KDE application we use ktimetracker from the kdepim module, other applications short work analog.
Using this description you will be able to
- update your working copy of KDE source code using the command svn
- build your KDE module using cmake
- build your KDE application from within eclipse using make
- compile and run your application with one click from eclipse
- get auto-completion when editing KDE source code
- have an overview and navigation about your classes within eclipse
- have call trees for your functions
Set up Eclipse with KDE
- Check your requirements
- Trying with a virtual machine I had problems starting Eclipse with less than 1 GB RAM. After assigning 3 GB RAM to my virtual machine, Eclipse finally started.
- Install eclipse
- Download Eclipse IDE for C/C++ developers from http://www.eclipse.org. We unpack it to /home/user/eclipse.
- Install the CDT
- Download the Eclipse IDE for C/C++ Developers (68 MB) from http://www.eclipse.org/cdt/ and unpack it into your eclipse folder, in our case /home/user/eclipse.
- Download kdepim
- As said, we use kdepim as example here. So, download ("checkout") kdepim using svn, e.g. as anonymous:
svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdepim
- We assume you checked out into /home/user/kdepim.
- Compile kdepim
- Compile kdepim so the usual makefiles are present for all kdepim applications. If you have problems doing this, follow our build instructions
- Import your project into eclipse
- Surprise: To import your project, you should not use "File -> Import". Rather do: File -> New -> C++ Project -> Makefile project -> Empty Project -> un-tag "use default location" -> choose /home/user/kdepim/ktimetracker. Call it "ktimetracker".
- Build your project
- Make sure Project -> Properties -> C/C++ Build -> Builder Settings -> Build location -> Build directory is set correctly.
- Choose Project -> Build Project
- Run the project
- Choose Project -> Properties -> Run/Debug Settings -> New. As project, enter ktimetracker, as C/C++ Application, enter /home/user/kdepim/ktimetracker/ktimetracker. Choose Apply -> Ok -> Ok. Now you can click on the "Run" button and start it.
Know-How
Custom builders
If you want to integrate the cmake build step into your build toolchain, you will need to
- create a custom builder like this:
cat >/bin/eclipsebuild<<EOF cmake . && make -j4 && make install EOF chmod 777 /bin/eclipsebuild
- Add your builder
- Choose Project -> Properties -> Builders. Un-tag all existing builders. Click "new" -> Program -> (name it "Builder for KDE"). -> Location: /bin/eclipsebuild -> Working directory /home/user/workspace/myproject1/kdepim.
- Build
- Now you can build your project. Every time after you restarted eclipse, choose myproject1 -> Project -> Properties -> C/C++ Build -> Ok -> Project -> Build.
Revert what eclipse did
To revert what eclipse did to your project simply run
rm -rf .externalToolBuilders/ .project .cproject
Why Subversion does not work
When using eclipse's svn plugin and building a KDE program, you will get error messages complaining that your svn binary is too old. If you want to try and change this, here's how you get to that error:
- Install the subversion plug-ins
- Help -> Software Updates -> Available Software -> Add Site -> http://download.eclipse.org/technology/subversive/0.7/update-site/ -> Add Site -> http://www.polarion.org/projects/subversive/download/eclipse/2.0/update-site/
- Now add it: Subversive Site -> Subversive SVN Team Provider Plugin
- Subversive SVN Connectors Site -> Subversive SVN Connectors -> SVNKit 1.3.0 Implementation (Optional)
- Click on Install
- Restart eclipse
- Import your KDE module
- Choose File -> New -> Other -> SVN -> Project from SVN -> https://svn.kde.org/home/kde/trunk/KDE/kdepim -> Check out as project configured using the New Project Wizard -> C++ Project -> Makefile Project -> Empty Project. As name, we choose kdepim5 -> Finish
- Set cmake as build environment
- Choose Project -> Properties -> C/C++ Build -> Builder Settings. Un-tag "use default build command", set "cmake" instead. Choose Project -> Properties -> C/C++ Build -> Behavior. Replace "all" by ".".
另見
- http://javathreads.de/2008/07/subversion-unter-eclipse-ganymede-konfigurieren/
- http://nienhueser.de/blog/?p=19
Qt Creator
這裡說明如何使用 Qt Creator 開發 KDE 4 應用程式。It has been tested with QtCreator 1.2.80 and SUSE Linux 11.1 but should work same or similar with every combination.我們使用來自 kdepim 模塊的ktimetracker作為 KDE 應用程式的範例。
載入現有專案
我們使用 ktimetracker 作為範例專案。
- 匯入 CMakeLists.txt 檔案
File -> Open -> kdepim/CMakeLists.txt.
- 配置 Qt Creator 只建構 ktimetracker
Projects -> ktimetracker -> build settings -> Add a configuration ktimetracker.
As build directory choose /home/youruser/kdepim/ktimetracker. As arguments for cmake use ...
開始 KDE 專案
想要開始一個新的專案你需要告訴 Qt Creator 建構時使用 KDE 程式庫。因此,選擇 File -> New... 並創建您的專案。在這裡我們稱為yourproject。為了能夠使用 KDE 程式庫,在你的家目錄,cd 進入yourproject並修改 yourproject.pro。加上
LIBS += -lkdeui