KDevelop4/TipsAndTricks: Difference between revisions
(add: translate-Tags) |
ChristianW (talk | contribs) m (separate bold italic because from this point, message is rendered all in bold in the translation interface) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<languages /> | <languages /> | ||
<translate> | <translate> | ||
== Tips And Tricks == | == Tips And Tricks == <!--T:1--> | ||
=== Code Completion === | === Code Completion === <!--T:2--> | ||
<!--T:3--> | |||
While you have automatic code completion, requesting it manually is often a very good idea. Press <keycap>Ctrl + Space</keycap> and you'll get a detailed code completion list. Navigate with the arrow buttons (<keycap>Up</keycap>/<keycap>Down</keycap>) and press (and keep pressed) <keycap>Alt</keycap> to show documentation of the focused item. Press <keycap>Enter</keycap> to insert the item. | While you have automatic code completion, requesting it manually is often a very good idea. Press <keycap>Ctrl + Space</keycap> and you'll get a detailed code completion list. Navigate with the arrow buttons (<keycap>Up</keycap>/<keycap>Down</keycap>) and press (and keep pressed) <keycap>Alt</keycap> to show documentation of the focused item. Press <keycap>Enter</keycap> to insert the item. | ||
=== C++ Type Assistant === | === C++ Type Assistant === <!--T:4--> | ||
<!--T:5--> | |||
Assume you have something similar to this: | Assume you have something similar to this: | ||
</translate> | </translate> | ||
Line 18: | Line 20: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
<!--T:6--> | |||
Now you want to iterate over the contents, instead of writing the type of the iterator, you just write: | Now you want to iterate over the contents, instead of writing the type of the iterator, you just write: | ||
</translate> | </translate> | ||
Line 24: | Line 27: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
<!--T:7--> | |||
Now wait a second until the assistant pops up at the bottom of the editor. Press <keycap>Alt + 1</keycap> to execute the assistant and you end up with: | Now wait a second until the assistant pops up at the bottom of the editor. Press <keycap>Alt + 1</keycap> to execute the assistant and you end up with: | ||
</translate> | </translate> | ||
Line 30: | Line 34: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
<!--T:8--> | |||
Nice, lots of time saved. {{Smiley}} And this should work with most/all expressions, as long as the right side can be evaluated, you should get an assistant that adds the correct type to the left side. | Nice, lots of time saved. {{Smiley}} And this should work with most/all expressions, as long as the right side can be evaluated, you should get an assistant that adds the correct type to the left side. | ||
=== C++ Signature Assistant === | === C++ Signature Assistant === <!--T:9--> | ||
<!--T:10--> | |||
Example code: | Example code: | ||
</translate> | </translate> | ||
Line 46: | Line 52: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
<!--T:11--> | |||
Now try the following things and after each step wait shortly and apply the assistant that pops up at the bottom of the editor with <keycap>Alt + 1</keycap>: | Now try the following things and after each step wait shortly and apply the assistant that pops up at the bottom of the editor with <keycap>Alt + 1</keycap>: | ||
<!--T:12--> | |||
# add a parameter, e.g. <code>int foo</code> to either signature in the definition or the declaration. | # add a parameter, e.g. <code>int foo</code> to either signature in the definition or the declaration. | ||
# make one signature <code>const</code> | # make one signature <code>const</code> | ||
Line 53: | Line 61: | ||
# remove a parameter | # remove a parameter | ||
<!--T:13--> | |||
Again, a very handy time saver! | Again, a very handy time saver! | ||
=== C++ Missing Declaration Assistant === | === C++ Missing Declaration Assistant === <!--T:14--> | ||
<!--T:15--> | |||
Example Code: | Example Code: | ||
</translate> | </translate> | ||
Line 69: | Line 79: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
<!--T:16--> | |||
Now write this into the implementation of bar: | Now write this into the implementation of bar: | ||
</translate> | </translate> | ||
Line 75: | Line 86: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
<!--T:17--> | |||
You should get an assistant that offers you three options: | You should get an assistant that offers you three options: | ||
<!--T:18--> | |||
# declare local <code>int myVar</code> (see type assistant above) | # declare local <code>int myVar</code> (see type assistant above) | ||
# declare public <code>int myVar</code>, adds the declaration to the class body | # declare public <code>int myVar</code>, adds the declaration to the class body | ||
# declare private <code>int myVar</code>, same as above, but in private section. | # declare private <code>int myVar</code>, same as above, but in private section. | ||
<!--T:19--> | |||
This even works for functions: | This even works for functions: | ||
</translate> | </translate> | ||
Line 93: | Line 107: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
<!--T:20--> | |||
Now write this below <code>foo f;</code>: | Now write this below <code>foo f;</code>: | ||
</translate> | </translate> | ||
Line 99: | Line 114: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
<!--T:21--> | |||
The assistant now offers you to declare that function, you'll end up with: | The assistant now offers you to declare that function, you'll end up with: | ||
</translate> | </translate> | ||
Line 108: | Line 124: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
<!--T:22--> | |||
Cool {{Smiley}}. | Cool {{Smiley}}. | ||
=== Overload Helper === | === Overload Helper === <!--T:23--> | ||
<!--T:24--> | |||
Example code: | Example code: | ||
</translate> | </translate> | ||
Line 125: | Line 143: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
Inside the class body of <code>B</code> press <keycap>Ctrl + Space</keycap> to bring up code completion. You should notice an item to overload <code>foo(int something);</code>. Execute it with | <!--T:25--> | ||
Inside the class body of <code>B</code> press <keycap>Ctrl + Space</keycap> to bring up code completion. You should notice an item to overload <code>foo(int something);</code>. Execute it with <keycap>Enter</keycap> and you should get: | |||
</translate> | </translate> | ||
{{Input|<syntaxhighlight lang="cpp"> | {{Input|<syntaxhighlight lang="cpp"> | ||
Line 134: | Line 153: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
<!--T:26--> | |||
Cool {{Smiley}}. | Cool {{Smiley}}. | ||
=== Implementation Helper === | === Implementation Helper === <!--T:27--> | ||
<!--T:28--> | |||
Continue where we left of in the '''Overload Helper''': | Continue where we left of in the '''Overload Helper''': | ||
</translate> | </translate> | ||
Line 147: | Line 168: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
Place your cursor below the class context, request code completion with <keycap>Ctrl + Space</keycap>, you should notice an item to implement <code>B::foo(int something);</code>. Execute it with | <!--T:29--> | ||
Place your cursor below the class context, request code completion with <keycap>Ctrl + Space</keycap>, you should notice an item to implement <code>B::foo(int something);</code>. Execute it with <keycap>Enter</keycap> and you should get: | |||
</translate> | </translate> | ||
{{Input|<syntaxhighlight lang="cpp"> | {{Input|<syntaxhighlight lang="cpp"> | ||
Line 156: | Line 178: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
<translate> | <translate> | ||
<!--T:30--> | |||
Awesome {{Smiley}}. | Awesome {{Smiley}}. | ||
=== Quick Open === | === Quick Open === <!--T:31--> | ||
<!--T:32--> | |||
<menuchoice>Quick Open</menuchoice> is probably one of ''the'' features in '''KDevelop''' that increases productivity: | <menuchoice>Quick Open</menuchoice> is probably one of ''the'' features in '''KDevelop''' that increases productivity: | ||
<!--T:33--> | |||
* Quick Open Files | * Quick Open Files | ||
Press <keycap>Ctrl + Alt + O</keycap> and type part of a filepath, press | Press <keycap>Ctrl + Alt + O</keycap> and type part of a filepath, press <keycap>Enter</keycap> and the selected file gets opened. The search is separated by forward slashes, i.e. you can write this: <code>/a/.cpp</code> and the list will only show paths that have a folder starting with <code>a</code> and files that end on <code>.cpp</code>. Try it out. | ||
<!--T:34--> | |||
* Quick Open Classes | * Quick Open Classes | ||
<keycap>Ctrl + Alt + C</keycap> and input (parts) of the qualified class identifier, press <keycap>Return</keycap> and jump to the declaration of that class. | <keycap>Ctrl + Alt + C</keycap> and input (parts) of the qualified class identifier, press <keycap>Return</keycap> and jump to the declaration of that class. | ||
<!--T:35--> | |||
Also make sure to explore the other advanced features in <menuchoice>Quick Open</menuchoice>. | Also make sure to explore the other advanced features in <menuchoice>Quick Open</menuchoice>. | ||
=== Outline === | === Outline === <!--T:36--> | ||
<!--T:37--> | |||
Similar to quick open, pressing <keycap>Ctrl + Alt + N</keycap> gives you an outline of the current document with the ability to search for an identifier and quickly jump to its declaration. | Similar to quick open, pressing <keycap>Ctrl + Alt + N</keycap> gives you an outline of the current document with the ability to search for an identifier and quickly jump to its declaration. | ||
=== Context Browsing === | === Context Browsing === <!--T:38--> | ||
Hover a use, declaration or definition and you'll get a popup with information about it. You can also move your cursor in there and press (and keep pressed) the <keycap>Alt</keycap> button to show that popup without using the mouse. Use the arrow keys to navigate between the links in the popup, use | <!--T:39--> | ||
Hover a use, declaration or definition and you'll get a popup with information about it. You can also move your cursor in there and press (and keep pressed) the <keycap>Alt</keycap> button to show that popup without using the mouse. Use the arrow keys to navigate between the links in the popup, use <keycap>Enter</keycap> to jump to the destination of a link. | |||
<!--T:40--> | |||
When inside a use, press <keycap>Meta + Left</keycap> or <keycap>Meta + Right</keycap> to jump to the previous/next use. Press <keycap>Ctrl + .</keycap> or <keycap>Ctrl + ,</keycap> to jump to the declaration or definition of the symbol under the cursor. Alternatively click on a symbol with <keycap>Ctrl</keycap> button pressed to do the same. | When inside a use, press <keycap>Meta + Left</keycap> or <keycap>Meta + Right</keycap> to jump to the previous/next use. Press <keycap>Ctrl + .</keycap> or <keycap>Ctrl + ,</keycap> to jump to the declaration or definition of the symbol under the cursor. Alternatively click on a symbol with <keycap>Ctrl</keycap> button pressed to do the same. | ||
Also take a look at the Navigation menu and it's various shortcuts. Context browsing is awesome! | <!--T:41--> | ||
Also take a look at the <menuchoice>Navigation</menuchoice> menu and it's various shortcuts. Context browsing is awesome! | |||
=== How to work with autotools: automake, autoconf and libtool === | === How to work with autotools: automake, autoconf and libtool === <!--T:42--> | ||
<!--T:43--> | |||
'''KDevelop 4''' does not support very well the autotools. I suggest using [[Special:myLanguage/Konsole|Konsole]] to run configure scripts to build makefile. The custom makefile support works quite well. I suggest using separate building folder (say <tt>project/build</tt>). | |||
After the custom makefiles are in place (say in | <!--T:44--> | ||
After the custom makefiles are in place (say in <tt>build</tt>-directory) one can add that to build list by clicking the {{Plus}} button on lower left corner '''Project selection''' while build directory is selected. This causes command '''make''' to be run when pressing <menuchoice>Build</menuchoice>. One can also directly run say '''make install''' on specific directory by right clicking the folder and selecting '''make install'''. This is nice if you have lots of projects in working set. | |||
'''Libtool''' also causes problems if you try to debug application that has been linked with '''libtool''': the program that see in for example | <!--T:45--> | ||
'''Libtool''' also causes problems if you try to debug application that has been linked with '''libtool''': the program that you see in for example <tt>src/bin/program</tt> is not the executable, but a script that handles the libraries. | |||
Problem is properly solved in console by running {{Input|1=libtool --mode=execute '''''<dst_binary>'''''}} but at least currently '''KDevelop4''' does not work good (at all) with other console than default. I have been stuck of using the real binary (found usually from | <!--T:46--> | ||
Problem is properly solved in console by running {{Input|1=libtool --mode=execute'' '''<dst_binary>''' ''}} but at least currently '''KDevelop4''' does not work good (at all) with other console than default. I have been stuck of using the real binary (found usually from <tt>src/bin/.libs/<exec></tt>) that might use wrong libraries, so do '''make install''' before every run. | |||
=== KDE Classes Documentation === | === KDE Classes Documentation === <!--T:47--> | ||
Using the '''Qt Documentation''' plugin you may integrate KDE documentation along with Qt documentation. Point your browser at [http://api.kde.org/ KDE API Reference] and download the desired .qch file (not all modules provide one). Then configure the '''Qt Documentation''' plugin by adding the downloaded files. That's it! Whenever you hover a KDE class you can see a link <menuchoice>Show documentation for KFooClass</menuchoice> which points to KFooClass documentation. Enjoy. | <!--T:48--> | ||
Using the '''Qt Documentation''' plugin you may integrate KDE documentation along with Qt documentation. Point your browser at [http://api.kde.org/ KDE API Reference] and download the desired <tt>.qch</tt> file (not all modules provide one). Then configure the '''Qt Documentation''' plugin by adding the downloaded files. That's it! Whenever you hover a KDE class you can see a link <menuchoice>Show documentation for KFooClass</menuchoice> which points to KFooClass documentation. Enjoy. | |||
<!--T:49--> | |||
[[Category:Development]] | [[Category:Development]] | ||
</translate> | </translate> |
Latest revision as of 11:42, 30 July 2018
Tips And Tricks
Code Completion
While you have automatic code completion, requesting it manually is often a very good idea. Press Ctrl + Space and you'll get a detailed code completion list. Navigate with the arrow buttons (Up/Down) and press (and keep pressed) Alt to show documentation of the focused item. Press Enter to insert the item.
C++ Type Assistant
Assume you have something similar to this:
#include <vector> void myFunc(const std::vector<int>& v) { }
Now you want to iterate over the contents, instead of writing the type of the iterator, you just write:
it = vector.begin();
Now wait a second until the assistant pops up at the bottom of the editor. Press Alt + 1 to execute the assistant and you end up with:
std::vector< int >::iterator it = v.begin();
Nice, lots of time saved. And this should work with most/all expressions, as long as the right side can be evaluated, you should get an assistant that adds the correct type to the left side.
C++ Signature Assistant
Example code:
class foo { int bar(); }; int foo::bar() { }
Now try the following things and after each step wait shortly and apply the assistant that pops up at the bottom of the editor with Alt + 1:
- add a parameter, e.g.
int foo
to either signature in the definition or the declaration. - make one signature
const
- change a type of a parameter
- remove a parameter
Again, a very handy time saver!
C++ Missing Declaration Assistant
Example Code:
class foo { int bar(); }; foo::bar() { }
Now write this into the implementation of bar:
myVar = 1;
You should get an assistant that offers you three options:
- declare local
int myVar
(see type assistant above) - declare public
int myVar
, adds the declaration to the class body - declare private
int myVar
, same as above, but in private section.
This even works for functions:
class foo { }; int main() { foo f; }
Now write this below foo f;
:
f.someFunction(1, true, "asdf");
The assistant now offers you to declare that function, you'll end up with:
class foo { public: void someFunction( int arg1, bool arg2, const char* arg3 ); };
Overload Helper
Example code:
class A { public: virtual A* foo(int something){} }; class B : public A { };
Inside the class body of B
press Ctrl + Space to bring up code completion. You should notice an item to overload foo(int something);
. Execute it with Enter and you should get:
class B : public A { public: virtual A* foo(int something); };
Implementation Helper
Continue where we left of in the Overload Helper:
class B : public A { public: virtual A* foo(int something); };
Place your cursor below the class context, request code completion with Ctrl + Space, you should notice an item to implement B::foo(int something);
. Execute it with Enter and you should get:
A* B::foo(int something) { A::foo(something); }
Quick Open
is probably one of the features in KDevelop that increases productivity:
- Quick Open Files
Press Ctrl + Alt + O and type part of a filepath, press Enter and the selected file gets opened. The search is separated by forward slashes, i.e. you can write this: /a/.cpp
and the list will only show paths that have a folder starting with a
and files that end on .cpp
. Try it out.
- Quick Open Classes
Ctrl + Alt + C and input (parts) of the qualified class identifier, press Return and jump to the declaration of that class.
Also make sure to explore the other advanced features in
.Outline
Similar to quick open, pressing Ctrl + Alt + N gives you an outline of the current document with the ability to search for an identifier and quickly jump to its declaration.
Context Browsing
Hover a use, declaration or definition and you'll get a popup with information about it. You can also move your cursor in there and press (and keep pressed) the Alt button to show that popup without using the mouse. Use the arrow keys to navigate between the links in the popup, use Enter to jump to the destination of a link.
When inside a use, press Meta + Left or Meta + Right to jump to the previous/next use. Press Ctrl + . or Ctrl + , to jump to the declaration or definition of the symbol under the cursor. Alternatively click on a symbol with Ctrl button pressed to do the same.
Also take a look at the
menu and it's various shortcuts. Context browsing is awesome!How to work with autotools: automake, autoconf and libtool
KDevelop 4 does not support very well the autotools. I suggest using Konsole to run configure scripts to build makefile. The custom makefile support works quite well. I suggest using separate building folder (say project/build).
After the custom makefiles are in place (say in build-directory) one can add that to build list by clicking the button on lower left corner Project selection while build directory is selected. This causes command make to be run when pressing . One can also directly run say make install on specific directory by right clicking the folder and selecting make install. This is nice if you have lots of projects in working set.
Libtool also causes problems if you try to debug application that has been linked with libtool: the program that you see in for example src/bin/program is not the executable, but a script that handles the libraries.
Problem is properly solved in console by running
libtool --mode=execute <dst_binary>
but at least currently KDevelop4 does not work good (at all) with other console than default. I have been stuck of using the real binary (found usually from src/bin/.libs/<exec>) that might use wrong libraries, so do make install before every run.
KDE Classes Documentation
Using the Qt Documentation plugin you may integrate KDE documentation along with Qt documentation. Point your browser at KDE API Reference and download the desired .qch file (not all modules provide one). Then configure the Qt Documentation plugin by adding the downloaded files. That's it! Whenever you hover a KDE class you can see a link which points to KFooClass documentation. Enjoy.