1 /****************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Free Documentation License
12 ** Alternatively, this file may be used under the terms of the GNU Free
13 ** Documentation License version 1.3 as published by the Free Software
14 ** Foundation and appearing in the file included in the packaging of this
17 ** If you have questions regarding the use of this file, please contact
18 ** Nokia at info@qt.nokia.com.
20 ****************************************************************************/
22 // **********************************************************************
23 // NOTE: the sections are not ordered by their logical order to avoid
24 // reshuffling the file each time the index order changes (i.e., often).
25 // Run the fixnavi.pl script to adjust the links to the index order.
26 // **********************************************************************
29 \contentspage index.html
30 \previouspage creator-project-managing-sessions.html
31 \page creator-coding.html
32 \nextpage creator-editor-using.html
36 Writing, editing, and navigating in source code are core tasks in
37 application development. Therefore, the code editor is one of the key
38 components of \QC. You can use the code editor in the \gui Edit
41 The following sections describe coding with \QC:
45 \o \l{Using the Editor} describes how to work in the code editor, use
46 the editor toolbar, split the view, add bookmarks, and move between
47 symbol definitions and declarations.
49 \o \l{Semantic Highlighting} describes highlighting code elements and
50 blocks, as well as using syntax highlighting also for other types
51 of files than C++ or QML.
53 \o \l{Checking Code Syntax} describes how errors are visualized
56 \o \l{Completing Code} describes how code and code snippets are
57 completed for elements, properties, an IDs.
59 \o \l{Indenting Code} describes how to specify indentation either
60 globally for all files or separately for: text, C++, or QML files.
62 \o \l{Finding and Replacing} describes the incremental search that
63 highlights the matching strings in the window while typing and the
64 advanced search that allows you to search from currently open
65 projects or files on the file system. In addition, you can search
66 for symbols when you want to refactor code.
68 \o \l{Refactoring} describes the features that help you improve the
69 internal quality or your application, its performance and
70 extendibility, and code readability and maintainability, as well as
71 to simplify code structure.
73 \o \l{Using Qt Quick Toolbars} describes how to use the Qt Quick
74 Toolbars to edit the properties of QML elements in the code editor.
76 \o \l{Searching With the Locator} describes how to browse through
77 projects, files, classes, methods, documentation and file systems.
79 \o \l{Pasting and Fetching Code Snippets} describes how to cooperate
80 with other developers by pasting and fetching snippets of code from
83 \o \l{Using Text Editing Macros} describes how to record and play
86 \o \l{Configuring the Editor} describes how to change the text editor
87 options to suit your specific needs.
89 \o \l{Using FakeVim Mode} describes how to run the main editor in a
90 manner similar to the Vim editor.
98 \contentspage index.html
99 \previouspage creator-coding.html
100 \page creator-editor-using.html
101 \nextpage creator-highlighting.html
103 \title Using the Editor
105 \QC's code editor is designed to aid you in creating, editing and
106 navigating code. \QC's code editor is fully equipped with syntax
107 checking, code completion, context sensitive help and in-line error
108 indicators while you are typing.
110 \image qtcreator-edit-mode.png "Edit mode"
112 \section1 Using the Editor Toolbar
114 The editor toolbar is located at the top of the editor view. The editor
115 toolbar is context sensitive and shows items relevant to the file currently
118 \image qtcreator-editortoolbar-symbols.png
120 Use the toolbar to navigate between open files and symbols in use.
121 To browse forward or backward through your location history, click
122 \inlineimage qtcreator-back.png
123 and \inlineimage qtcreator-forward.png
126 To go to any open file, select it from the \gui{Open files} drop-down menu.
127 Right-click the menu title and select \gui {Copy Full Path to Clipboard} to
128 copy the path and name of the current file to the clipboard.
130 To jump to any symbol used in the current file, select it from the
131 \gui Symbols drop-down menu. By default, the symbols are displayed in the
132 order in which they appear in the file. Right-click the menu title and
133 select \gui {Sort Alphabetically} to arrange the symbols in alphabetic
136 \section1 Splitting the Editor View
138 Split the editor view when you want to work on and view multiple files on
141 \image qtcreator-spliteditorview.png
143 You can split the editor view in the following ways:
147 \o To split the editor view into a top and bottom view, select
148 \gui Window > \gui Split or press \key{Ctrl+E, 2}.
150 Split command creates views below the currently active editor view.
152 \o To split the editor view into adjacent views, select
153 \gui Window > \gui{Split Side by Side} or press \key{Ctrl+E, 3}.
155 Side by side split command creates views to the right of the
156 currently active editor view.
160 To move between split views, select \gui Window > \gui{Go to Next Split} or
161 press \key{Ctrl+E, O}.
163 To remove a split view, place the cursor within the view you want to
164 remove and select \gui Window > \gui{Remove Current Split} or press
165 \key{Ctrl+E, 0}. To remove all but the currently selected split view,
166 select \gui Window > \gui{Remove All Splits} or press \key{Ctrl+E, 1}.
168 \section1 Using Bookmarks
170 To insert or delete a bookmark right-click the line number and select
171 \gui{Toggle Bookmark} or press \key{Ctrl+M}.
173 \image qtcreator-togglebookmark.png
175 To go to previous bookmark in the current session, press \key{Ctrl+,}.
177 To go to next bookmark in the current session, press \key{Ctrl+.}.
179 \section1 Moving to Symbol Definition or Declaration
181 You can move directly to the definition or the declaration of a symbol by
182 holding the \key Ctrl and clicking the symbol.
184 To enable this moving function, in \gui Tools > \gui{Options} >
185 \gui{Text Editor} > \gui Behavior, select \gui{Enable mouse navigation}.
187 You can also select the symbol and press \key F2, or right-click the symbol
188 and select \gui {Follow Symbol Under Cursor} to move to its definition or
189 declaration. This feature is supported for namespaces, classes, methods,
190 variables, include statements, and macros.
192 To switch between the definition and declaration of a symbol, press
193 \key {Shift+F2} or right-click the symbol and select \gui {Switch Between
194 Method Declaration/Definition}.
196 \section1 Using Update Code Model
198 To refresh the internal information in \QC pertaining to your code,
199 select \gui{Tools} > \gui{C++} > \gui{Update Code Model}.
201 \note In \QC indexing updates the code automatically. Use
202 \gui{Update Code Model} only as an emergency command.
207 \contentspage index.html
208 \previouspage creator-editor-using.html
209 \page creator-highlighting.html
210 \nextpage creator-checking-code-syntax.html
212 \title Semantic Highlighting
214 \QC understands the C++ and QML languages as code, not as plain text.
215 It reads the source code, analyzes it, and highlights it based on the
216 semantic checks that it does for the following code elements:
220 \o Types (such as classes, structs, and type definitions)
230 To specify the color scheme to use for semantic highlighting, select
231 \gui {Tools > Options > Text Editor > Fonts & Color}.
233 \QC supports syntax highlighting also for other types of files than
236 \section1 Generic Highlighting
238 Generic highlighting is based on highlight definition files that are
240 \l{http://kate-editor.org/2005/03/24/writing-a-syntax-highlighting-file/}
241 {Kate Editor}. You can download highlight definition files for use with \QC.
243 If you have a Unix installation that comes with the Kate Editor, you might
244 already have the definition files installed. Typically, the files are
245 located in a read-only directory, and therefore, you cannot manage them. \QC
246 can try to locate them and use them as fallback files, when the
247 primary location does not contain the definition for the current file type.
248 You can also specify the directory that contains preinstalled highlight
249 definition files as the primary location.
251 When you open a file for editing and the editor cannot find the highlight
252 definition for it, an alert appears. You can turn off the alerts. You can
253 also specify patterns for ignoring files. The editor will not alert you if
254 highlight definitions for the ignored files are not found.
256 To download highlight definition files:
260 \o Select \gui {Tools > Options > Text Editor > Generic
263 \image qtcreator-generic-highlighter.png "Generic Highlighter options"
265 \o In the \gui Location field, specify the path to the primary
266 location for highlight definition files.
268 \o Click \gui {Download Definitions} to open a list of highlight
269 definition files available for download.
271 \image qtcreator-manage-definitions.png "Download Definitions dialog"
273 \o Select highlight definition files in the list and click
274 \gui {Download Selected Definitions}.
276 \o Select the \gui {Use fallback location} check box to specify the
277 secondary location where the editor will look for highlight
280 \o Click \gui Autodetect to allow \QC to look for highlight
281 definition files on your system, or click \gui Browse to locate
282 them in the file system yourself.
284 \o In the \gui {Ignored file patterns} field, specify file patterns.
285 You will not receive alerts if the highlight definitions for the
286 specified files are not found.
288 \o Click \gui OK to save your changes.
292 \section1 Highlighting and Folding Blocks
294 Use block highlighting to visually separate parts of the code that belong
295 together. For example, when you place the cursor within the braces,
296 the code enclosed in braces is highlighted.
298 \image qtcreator-blockhighlighting.png
300 To enable block highlighting, select \gui Tools > \gui{Options} >
301 \gui{Text Editor} > \gui Display > \gui{Highlight blocks}.
303 Use the folding markers to collapse and expand blocks of code within
304 braces. Click the folding marker to collapse or expand a block. In the
305 figure above, the folding markers are located between the line number and
308 To show the folding markers, select \gui Tools > \gui{Options} >
309 \gui{Text Editor} > \gui Display > \gui{Display folding markers}. This
310 option is enabled by default.
312 When the cursor is on a brace, the matching brace is animated
313 by default. To turn off the animation and just highlight the block and
314 the braces, select \gui {Tools > Options > Text Editor > Display} and
315 deselect \gui {Animate matching parentheses}.
321 \contentspage index.html
322 \previouspage creator-highlighting.html
323 \page creator-checking-code-syntax.html
324 \nextpage creator-completing-code.html
326 \title Checking Code Syntax
328 As you write code \QC checks code syntax. When \QC spots a syntax error in
329 your code it underlines it and shows error details when you move the mouse
330 pointer over the error.
334 \o Syntax errors are underlined in red.
336 In the following figure, a semicolon is missing at the end of the
339 \image qtcreator-syntaxerror.png
341 \o Semantic errors and warnings are underlined in olive.
343 In the following figure, the type is unknown.
345 \image qtcreator-semanticerror.png
349 \section1 Checking JavaScript Syntax
351 You can run static checks on JavaScript to find common problems, such as:
355 \o Duplicate or conflicting variable, function, and formal parameter
358 \o Variables and functions that are used before they are declared
360 \o Possibly unsafe uses of the == or != operators
362 \o Comma expressions, except in \c for statements
364 \o Expression statements, except function or method calls, assignments,
367 \o Assignments within conditions (such as, \c {if (a = b)})
369 \o Case blocks within a switch that do not end with a return, break,
370 continue, or throw and that are not empty
372 \o Nested block statements
374 \o \c with statements
376 \o \c void expressions
380 To run the checks, select \gui {Tools > QML/JS > Run Checks} or press
381 \key Ctrl+Shift+C. The results are shown in the \gui {QML Analysis}
382 filter of the \gui {Issues} output pane.
388 \contentspage index.html
389 \previouspage creator-checking-code-syntax.html
390 \page creator-completing-code.html
391 \nextpage creator-indenting-code.html
393 \title Completing Code
395 As you write code, \QC suggests properties, IDs, and code snippets to
396 complete the code. It provides a list of context-sensitive suggestions to
397 the statement currently under your cursor. Press \key Tab
398 or \key Enter to accept the selected suggestion and complete the code.
400 \image qtcreator-codecompletion.png
402 To open the list of suggestions at any time, press \key{Ctrl+Space}.
403 If only one option is available, \QC inserts it automatically.
405 When completion is invoked manually, \QC completes the common prefix
406 of the list of suggestions. This is especially useful for classes with
407 several similarly named members. To disable this functionality, uncheck
408 \gui{Autocomplete common prefix} in the code completion preferences.
409 Select \gui Tools > \gui{Options} > \gui{Text Editor} > \gui Completion.
411 By default, code completion considers only the first letter case-sensitive.
412 To apply full or no case-sensitivity, select the option in the
413 \gui {Case-sensitivity} field.
415 \section2 Summary of Available Types
417 The following table lists available types for code completion and icon
425 \i \inlineimage completion/class.png
428 \i \inlineimage completion/enum.png
431 \i \inlineimage completion/enumerator.png
432 \i An enumerator (value of an enum)
434 \i \inlineimage completion/func.png
437 \i \inlineimage completion/func_priv.png
438 \i A private function
440 \i \inlineimage completion/func_prot.png
441 \i A protected function
443 \i \inlineimage completion/var.png
446 \i \inlineimage completion/var_priv.png
447 \i A private variable
449 \i \inlineimage completion/var_prot.png
450 \i A protected variable
452 \i \inlineimage completion/signal.png
455 \i \inlineimage completion/slot.png
458 \i \inlineimage completion/slot_priv.png
461 \i \inlineimage completion/slot_prot.png
464 \i \inlineimage completion/keyword.png
467 \i \inlineimage completion/snippet.png
468 \i A C++ code snippet
470 \i \inlineimage completion/element.png
473 \i \inlineimage completion/qmlsnippet.png
474 \i A QML code snippet
476 \i \inlineimage completion/macro.png
479 \i \inlineimage completion/namespace.png
483 \section2 Completing Code Snippets
485 Code snippets can consist of multiple
486 variables that you specify values for. Select an item in the list and press
487 \key Tab or \key Enter to complete the code. Press \key Tab to
488 move between the variables and specify values for them. When you specify a
489 value for a variable, all instances of the variable within the snippet
492 \image qmldesigner-code-completion.png "Completing QML code"
494 \section2 Editing Code Snippets
496 Code snippets specify C++ or QML code constructs. You can add, modify,
497 and remove snippets in the snippet editor. To open the editor, select
498 \gui {Tools > Options > Text Editor > Snippets}.
500 \image qtcreator-edit-code-snippets.png "Snippet options"
502 \QC provides you with built-in snippets in the following categories:
506 \o Text snippets, which can contain any text string. For example, code
509 \o C++ code snippets, which specify C++ code constructs
511 \o QML code snippets, which specify QML code constructs
515 \section3 Adding and Editing Snippets
517 Select a snippet in the list to edit it in the snippet editor. To add a new
518 snippet, select \gui Add. Specify a trigger and, if the trigger is already
519 in use, an optional variant, which appear in the list of suggestions when
520 you write code. Also specify a text string or C++ or QML code construct in
521 the snippet editor, depending on the snippet category.
523 The snippet editor provides you with:
531 \o Parentheses matching
533 \o Basic code completion
537 Specify the variables for the snippets in the following format:
541 Use unique variable names within a snippet, because all instances of a
542 variable are renamed when you specify a value for it.
544 The snippet editor does not check the syntax of the snippets that you edit
545 or add. However, when you use the snippets, the code editor marks any
546 errors by underlining them in red.
548 To discard the changes you made to a built-in snippet, select \gui {Revert
551 \section3 Removing Snippets
553 Several similar built-in snippets might be provided for different use
554 cases. To make the list of suggestions shorter when you write code, remove
555 the built-in snippets that you do not need. If you need them later, you
558 To remove snippets, select a snippet in the list, and then select
559 \gui Remove. To restore the removed snippets, select \gui {Restore Removed
562 \section3 Resetting Snippets
564 To remove all added snippets and to restore all removed snippets, select
567 \note If you now select \gui OK or \gui Apply, you permanently lose all
574 \contentspage index.html
575 \previouspage creator-editor-locator.html
576 \page creator-editor-codepasting.html
577 \nextpage creator-macros.html
579 \title Pasting and Fetching Code Snippets
581 In \QC, you can paste snippets of code to a server or fetch snippets of code
582 from the server. To paste and fetch snippets of code, \QC uses the
589 \o \gui{Pastebin.Com}
595 To configure the server, select \gui{Tools} > \gui{Options} >
598 To paste a snippet of code onto the server, select \gui{Tools} >
599 \gui{Code Pasting} > \gui{Paste Snippet} or press \key{Alt+C,Alt+P}.
601 To fetch a snippet of code from the server, select \gui{Tools} >
602 \gui{Code Pasting} > \gui{Fetch Snippet} or press \key{Alt+C,Alt+F}.
604 \note To use \gui{Pastebin.Com}, configure the domain
605 prefix in \gui{Tools} > \gui{Options} > \gui{Code Pasting} >
608 For example, you might ask colleagues to review a change that you plan to
609 submit to a version control system. If you use the Git version control
610 system, you can create a \e{diff} view by selecting \gui{Tools > Git >
611 Diff Repository}. You can then upload its contents to the server by choosing
612 \gui{Tools} > \gui{Code Pasting} > \gui{Paste Snippet}. The reviewers can
613 retrieve the code snippet by selecting \gui{Tools > Code Pasting >
614 Fetch Snippet}. If they have the project currently opened in \QC, they can
615 apply and test the change by choosing \gui{Tools > Git > Apply Patch}.
621 \contentspage index.html
622 \previouspage creator-editor-codepasting.html
623 \page creator-macros.html
624 \nextpage creator-editor-options.html
626 \title Using Text Editing Macros
628 When you have a file open in the code editor, you can record a keyboard
629 sequence as a macro. You can then play the macro to repeat the sequence.
630 You can save the latest macro and assign a keyboard shortcut for running
631 it or run it from the locator.
633 To record a text editing macro, select \gui {Tools > Macros > Record Macro}
634 or press \key {Alt+(}. To stop recording, select \gui {Tools > Macros >
635 Stop Recording Macro} or press \key {Alt+)}.
637 To play the last macro, select \gui {Tools > Macros > Play Last Macro} or
640 To save the last macro, select \gui {Tools > Macros > Save Last Macro}.
642 To assign a keyboard shortcut to a text editing macro, select \gui {Tools >
643 Options > Environment > Keyboard}. For more information, see
644 \l{Configuring Keyboard Shortcuts}.
646 You can also use the \c rm locator filter to run a macro. For more
647 information, see \l{Searching With the Locator}.
649 To view and remove saved macros, select \gui {Tools > Options > Text
656 \contentspage index.html
657 \previouspage creator-editor-options.html
658 \page creator-editor-fakevim.html
659 \nextpage creator-design-mode.html
661 \title Using FakeVim Mode
663 In the \gui{FakeVim} mode, you can run the main editor in a manner similar
664 to the Vim editor. To run the editor in the \gui{FakeVim} mode, select
665 \gui{Edit} > \gui{Advanced} > \gui{Use Vim-style Editing} or press
668 In the \gui{FakeVim} mode, most keystrokes in the main editor will be
669 intercepted and interpreted in a way that resembles Vim. Documentation for
670 Vim is not included in \QC. For more information on using Vim,
671 see \l{http://www.vim.org/docs.php}{Documentation} on the Vim web site.
673 To map commands entered on the \gui{FakeVim} command line to actions of the
674 \QC core, select \gui{Tools} > \gui{Options} > \gui{FakeVim} >
675 \gui{Ex Command Mapping}.
677 To make changes to the Vim-style settings, select \gui{Tools} >
678 \gui{Options} > \gui FakeVim > \gui{General}.
680 To use a Vim-style color scheme, select \gui {Tools > Options >
681 Text Editor > Fonts & Color}. In the \gui {Color Scheme} list, select
684 To quit the FakeVim mode, unselect \gui{Tools} > \gui(Options} >
685 \gui{FakeVim} > \gui {Use FakeVim} or press \key{Alt+V,Alt+V}.
687 You can temporarily escape FakeVim mode to access the normal \QC
688 keyboard shortcuts like \key{Ctrl-R} for \gui{Run} by pressing
695 \contentspage index.html
696 \previouspage creator-macros.html
697 \page creator-editor-options.html
698 \nextpage creator-editor-fakevim.html
700 \title Configuring the Editor
702 \QC allows you to configure the text editor to suit your specific
703 needs. To configure the editor, select \gui Tools > \gui{Options} >
706 These settings apply to all projects. To specify editor behavior for an
707 open project, select \gui {Projects > Editor Settings}. For more
708 information, see \l{Specifying Editor Settings}.
710 You can also specify indentation settings separately for C++ and QML files
711 either globally or for the open project. For more information, see
714 \image qtcreator-font-colors.png "Text editor options"
716 You can perform the following configuration actions:
720 \o Set the font preferences and apply color schemes for syntax
721 highlighting in \gui{Font & Colors}.
723 \o Specify \l{Generic Highlighting}
724 {definition files for syntax highlighting} for other types of files
725 than C++ or QML in \gui{Generic Highlighter}.
727 \o Set tabs, indentation, the handling of whitespace, and mouse
728 operations in \gui Behavior. For more information, see
731 \o Set various display properties, for example,
732 \l{Highlighting and folding blocks}
733 {highlighting and folding blocks}, text wrapping or
734 \l{Moving to symbol definition or declaration}
735 {moving to symbol definition or declaration} in \gui Display.
737 \o Add, modify, and remove \l{Editing Code Snippets}{code snippets} in
740 \o View and remove \l{Using Text Editing Macros}{text editing macros}
743 \o Configure \l{Completing Code}{code completion} in \gui Completion.
747 \section2 Configuring Fonts
749 You can select the font family and size. You can specify a zoom setting in
750 percentage for viewing the text. You can also zoom in or out by pressing
751 \key {Ctrl++} or \key {Ctrl +-}, or by pressing \key Ctrl and rolling
752 the mouse button up or down. To disable the mouse wheel function, select
753 \gui {Tools > Options > Text Editor > Behavior} and deselect the
754 \gui {Enable scroll wheel zooming} check box.
756 Antialiasing is used by default to make text look smoother and more
757 readable on the screen. Deselect the \gui Antialias check box to
758 turn off antialiasing.
760 \section2 Defining Color Schemes
762 You can select one of the predefined color schemes for syntax highlighting
763 or create customized color schemes. The color schemes apply to highlighting
764 both C++ and QML files and generic files.
766 To create a color scheme:
770 \o Select \gui {Tools > Options > Text Editor > Fonts & Color > Copy}.
772 \o Enter a name for the color scheme and click \gui OK.
774 \o In the \gui Foreground field, specify the color of the selected
777 \o In the \gui Background field, select the background
778 color for the code element.
780 The backgound of the \gui Text element determines the background of the
785 When you copy code from \QC, it is copied in both plain text and HTML
786 format. The latter makes sure that syntax highlighting is preserved when
787 pasting to a rich-text editor.
789 \section2 File Encoding
791 To define the default file encoding, select the desired encoding in
792 \gui {Default encoding}. By default, \QC uses the file encoding
799 \contentspage index.html
800 \previouspage creator-completing-code.html
801 \page creator-indenting-code.html
802 \nextpage creator-editor-finding.html
804 \title Indenting Code
806 When you type code, it is indented automatically according to the selected
807 text editor and code style options. Select a block to indent it when you
808 press \key Tab. Press \key {Shift+Tab} to decrease the indentation. You
809 can disable automatic indentation.
811 You can specify indentation either globally for all files or separately
824 You can also specify indentation separately for each project. You can
825 specify several sets of code style settings and easily switch between them.
826 In addition, you can import and export code style settings.
828 \section1 Indenting Text Files
830 To specify global indentation settings for the text editor, select
831 \gui {Tools > Options > Text Editor > Behavior}. You can also use these
832 settings globally for all editors and files.
834 \image qtcreator-indentation.png "Text Editor Behavior options"
836 To specify settings for a particular project, select \gui {Projects >
839 You can specify how to interpret the \key Tab and \key Backspace key
840 presses and how to align continuation lines.
842 \section1 Indenting C++ Files
844 To specify indentation settings for the C++ editor:
848 \o Select \gui {Tools > Options > C++}.
850 \o In the \gui {Current settings} field, select the settings to modify
853 \image qtcreator-options-code-style-cpp.png "C++ Code Style options"
855 \o Give a name to the settings and click \gui OK.
857 \o Click \gui Edit to specify code style settings for the project.
859 \image qtcreator-code-style-settings-edit-cpp.png "Edit Code Style Settings dialog"
864 You can specify how to:
868 \o Interpret the \key Tab and \key Backspace key presses.
870 \o Indent the contents of classes, methods, blocks, and namespaces.
872 \o Indent braces in classes, namespaces, enums, methods, and blocks.
874 \o Control switch statements and their contents.
876 \o Align continuation lines.
880 You can use the live preview to see how the options change the indentation.
882 To specify the settings for a particular project, select \gui {Projects >
883 Code Style Settings}.
885 \section1 Indenting QML Files
887 To specify global settings for the Qt Quick editor:
891 \o Select \gui {Tools > Options >Qt Quick}.
893 \o In the \gui {Current settings} field, select the settings to modify
896 \image qtcreator-options-code-style-qml.png "QML Code Style options"
898 \o Give a name to the settings and click \gui OK.
900 \o Click \gui Edit to specify code style settings for the project.
902 \image qtcreator-code-style-settings-edit-qtquick.png "Edit Code Style Settings dialog"
906 You can specify how to interpret the \key Tab key presses and how to align
909 To specify the settings for a particular project, select \gui {Projects >
910 Code Style Settings}.
912 \section1 Specifying Tab Settings
914 You can specify tab settings at the following levels:
918 \o Global settings for all files
920 \o Global C++ settings for C++ files
922 \o Global Qt Quick settings for QML files
924 \o Project specific settings for all editors of files in the project
926 \o Project specific settings for C++ files in the project
928 \o Project specific settings for QML files in the project
932 \section2 Specifying Tabs and Indentation
934 You can specify tab policy and tab size in the \gui Typing group. In the
935 \gui {Tab policy} field, select whether to use only spaces or only tabs for
936 indentation, or to use a mixture of them.
938 By default, the tab length in code editor is 8 spaces and the indent size is
939 4 spaces. You can specify the tab length and indent size separately for each
940 project and for different types of files.
942 You can have continuation lines aligned with the previous line. In the
943 \gui {Align continuation lines} field, select \gui {Not at all} to disable
944 automatic alignment and indent continuation lines to the logical depth.
945 To always use spaces for alignment, select \gui {With Spaces}. To follow the
946 \gui {Tab policy}, select \gui {With Regular Indent}.
948 \section2 Speficying Typing Options
950 When you type code, it is indented automatically according to the selected
951 text editor and code style options. Specify typing options in the
952 \gui Typing group. To disable automatic indentation, deselect the
953 \gui {Enable automatic indentation} check box.
955 You can specify how the indentation is decreased when you press
956 \gui Backspace in the \gui {Backspace indentation} field. To go back one
957 space at a time, select \gui None. To decrease indentation in leading white
958 space by one level, select \gui {Follows Previous Indents}. To move back one
959 tab length if the character to the left of the cursor is a space, select
962 You can specify whether the \key Tab key automatically indents text when you
963 press it. To automatically indent text, select \gui Always in the
964 \gui {Tab key performs auto-indent} field. To only indent text when the
965 cursor is located within leading white space, select \gui {In Leading White
968 \section1 Specifying Settings for Content
970 You can indent public, protected, and private statements and declarations
971 related to them within classes.
973 You can also indent statements within methods and blocks and declarations
976 \image qtcreator-code-style-content.png "Content options"
978 \section1 Specifying Settings for Braces
980 You can indent class, namespace, enum and method declarations and code
983 \image qtcreator-code-style-braces.png "Braces options"
985 \section1 Specifying Settings for Switch Statements
987 You can indent case or default statements, or statements or blocks related
988 to them within switch statements.
990 \image qtcreator-code-style-switch.png "Switch options"
992 \section1 Specifying Alignment
994 To align continuation lines to tokens after assignments, such as = or
995 +=, select the \gui {Align after assignments} check box. You can specify
996 additional settings for aligning continuation lines in the \gui General
999 You can also add spaces to conditional statements, so that they are not
1000 aligned with the following line. Usually, this only affects \c if
1003 \image qtcreator-code-style-alignment.png "Alignment options"
1009 \contentspage index.html
1010 \previouspage creator-indenting-code.html
1011 \page creator-editor-finding.html
1012 \nextpage creator-editor-refactoring.html
1014 \title Finding and Replacing
1016 To search through the currently open file:
1020 \o Press \key Ctrl+F or select \gui Edit > \gui Find/Replace >
1023 \o Enter the text you are looking for.
1025 If the text is found, all occurrences are highlighted as you type.
1027 \o To go to the next occurrence, click \inlineimage qtcreator-next.png
1028 , or press \key F3. To go to the previous occurrence click
1029 \inlineimage qtcreator-previous.png
1030 , or press \key Shift+F3.
1034 You can restrict the search in the \gui Find field by selecting one
1035 or several search criteria:
1039 \o To make your search case sensitive, select
1040 \inlineimage qtcreator-editor-casesensitive.png
1043 \o To search only whole words, select
1044 \inlineimage qtcreator-editor-wholewords.png
1047 \o To search using regular expressions, select
1048 \inlineimage qtcreator-editor-regularexpressions.png
1050 Regular expressions used in \QC are modeled on Perl regular
1051 expressions. For more information on using regular expressions, see
1052 \l {http://doc.qt.nokia.com/4.7/qregexp.html#details}
1053 {Detailed Description} in the QRegExp Class Reference.
1057 \note If you have selected text before selecting \gui Find/Replace, the
1058 search is conducted within the selection.
1060 To replace occurrences of the existing text, enter the new text in the
1061 \gui{Replace with} field.
1065 \o To replace the selected occurrence and move to the next one,
1066 click \inlineimage qtcreator-next.png
1067 or press \key Ctrl+=.
1069 \o To replace the selected occurrence and move to the previous one,
1070 click \inlineimage qtcreator-previous.png
1073 \o To replace all occurrences in the file, click \gui{Replace All}.
1077 \section1 Advanced Search
1079 To search through projects, files on a file system or the currently open
1084 \o Press \key Ctrl+Shift+F or select \gui Edit > \gui Find/Replace >
1085 \gui{Advanced Find} > \gui{Open Advanced Find}.
1087 \o Select the scope of your search:
1091 \o \gui{All Projects} searches files matching the defined file
1092 pattern in all currently open projects.
1094 For example, to search for \tt previewer only in \tt .cpp
1095 and \tt .h files, enter in \gui{File pattern}
1098 \image qtcreator-search-allprojects.png
1100 \o \gui{Current Project} searches files matching the defined
1101 file pattern only in the project you are currently editing.
1103 \o \gui{Files on File System} recursively searches files
1104 matching the defined file pattern in the selected directory.
1106 \o \gui{Current File} searches only the current file.
1110 \o Enter the text you are looking for and click \gui Search.
1112 \image qtcreator-searchresults.png
1114 A list of files containing the searched text is displayed in the
1115 \gui{Search Results} pane.
1119 \o To see all occurrences in a file, double-click the file name
1122 \o To go to an occurrence, double-click it.
1128 \note You can use \gui{Advanced Find} also to search for symbols. For more
1129 information, see \l{Finding Symbols}.
1135 \contentspage index.html
1136 \previouspage creator-editor-finding.html
1137 \page creator-editor-refactoring.html
1138 \nextpage qt-quick-toolbars.html
1142 Code refactoring is the process of changing the code without modifying the
1143 existing functionality of your application. By refactoring your code you
1148 \o Improve internal quality of your application
1150 \o Improve performance and extensibility
1152 \o Improve code readability and maintainability
1154 \o Simplify code structure
1158 \section1 Finding Symbols
1160 To find the use of a specific symbol or \l{glossary-component}
1161 {QML component} in your Qt C++ or Qt Quick project:
1165 \o In the editor, place the cursor on the symbol or component, and
1170 \o \gui {Tools > C++ > Find Usages}
1172 \o \gui {Tools > QML/JS > Find Usages}
1174 \o \key Ctrl+Shift+U
1178 \QC looks for the symbol in the following locations:
1182 \o Files listed as a part of the project
1184 \o Files directly used by the project files (for example, generated
1187 \o Header files of used frameworks and libraries
1191 \note You can also select \gui{Edit > Find/Replace > Advanced Find >
1192 C++ Symbols} to search for classes, methods, enums, and declarations
1193 either from files listed as part of the project or from all files that
1194 are used by the code, such as include files.
1196 \image qtcreator-search-cpp-symbols.png
1198 \o The \gui{Search Results} pane opens and shows the location and
1199 number of instances of the symbol in the current project.
1201 \image qtcreator-refactoring-find.png
1205 You can browse the search results in the following ways:
1209 \o To go directly to an instance, double-click the instance in the
1210 \gui{Search Results} pane.
1212 \o To move between instances, click
1213 \inlineimage qtcreator-forward.png
1215 \inlineimage qtcreator-back.png
1216 in the \gui{Search Results} pane.
1218 \o To expand and collapse the list of all instances, click
1219 \inlineimage qtcreator-expand.png
1222 \o To clear the search results, click \inlineimage qtcreator-clear.png
1227 \section1 Renaming Symbols
1229 To rename a specific symbol in a Qt project:
1233 \o In the editor, place the cursor on the symbol you would like to
1234 change and select \gui Tools > \gui C++ >
1235 \gui{Rename Symbol Under Cursor} or \gui Tools > \gui QML/JS >
1236 \gui{Rename Symbol Under Cursor}. Alternatively, press
1239 The \gui{Search Results} pane opens and shows the location and
1240 number of instances of the symbol in the current project.
1242 \image qtcreator-refactoring-replace.png
1244 \o To replace all selected instances, enter the name of the new symbol
1245 in the \gui{Replace with} text box and click \gui Replace.
1247 To omit an instance, uncheck the check-box next to the instance.
1249 \note This action replaces all selected instances of the symbol in
1250 all files listed in the \gui{Search Results} pane. You cannot
1255 \note Renaming local symbols does not open the \gui{Search Results} pane.
1256 The instances of the symbol are highlighted in code and you can edit the
1257 symbol. All instances of the local symbol are changed as you type.
1259 \section1 Applying Refactoring Actions
1261 \QC allows you to quickly and conveniently apply actions to refactor
1262 your code by selecting them in a context menu. The actions available depend
1263 on the position of the cursor in the code editor and on whether you are
1264 writing C++ or QML code.
1266 To apply refactoring actions to C++ code, right-click an operand,
1267 conditional statement, string, or name to open a context menu. In QML code,
1268 click an element ID or name.
1270 In the context menu, select \gui {Refactoring} and then select a refactoring
1273 You can also press \gui {Alt+Enter} to open a context menu that contains
1274 refactoring actions available in the current cursor position.
1276 \section2 Refactoring C++ Code
1278 You can apply the following types of refactoring actions to C++ code:
1282 \o Change binary operands
1284 \o Simplify if and while conditions (for example, move declarations out
1287 \o Modify strings (for example, set the encoding for a string to
1288 Latin-1, mark strings translatable, and convert symbol names to
1291 \o Create variable declarations
1293 \o Create method declarations and definitions
1297 The following table summarizes the refactoring actions for C++ code. The
1298 action is available when the cursor is in the position described in the
1303 \i Refactoring Action
1308 \i Adds curly braces to an if statement that does not contain a
1309 compound statement. For example, rewrites
1325 \i Move Declaration out of Condition
1326 \i Moves a declaration out of an if or while condition to simplify the
1327 condition. For example, rewrites
1330 if (Type name = foo()) {}
1339 \i Name of the introduced variable
1341 \i Rewrite Condition Using ||
1342 \i Rewrites the expression according to De Morgan's laws. For example,
1355 \i Rewrite Using \e operator
1356 \i Rewrites an expression negating it and using the inverse operator. For
1395 \i Split Declaration
1396 \i Splits a simple declaration into several declarations. For example,
1408 \i Type name or variable name
1410 \i Split if Statement
1411 \i Splits an if statement into several statements. For example, rewrites:
1413 if (something && something_else) {
1421 if (something_else) {
1429 if (something || something_else)
1438 else if (something_else)
1445 \i Rewrites an expression in the inverse order using the inverse operator.
1446 For example, rewrites:
1455 \i <= < > >= == != && ||
1457 \i Convert to Decimal
1458 \i Converts an integer literal to decimal representation
1461 \i Convert to Hexadecimal
1462 \i Converts an integer literal to hexadecimal representation
1466 \i Converts an integer literal to octal representation
1469 \i Convert to Objective-C String Literal
1470 \i Converts a string literal to an Objective-C string literal
1471 if the file type is Objective-C(++). For example, rewrites the following strings
1475 QLatin1String("abcd")
1476 QLatin1Literal("abcd")
1486 \i Enclose in QLatin1Char()
1487 \i Sets the encoding for a character to Latin-1, unless the character is
1488 already enclosed in QLatin1Char, QT_TRANSLATE_NOOP, tr, trUtf8,
1489 QLatin1Literal, or QLatin1String. For example, rewrites
1502 \i Enclose in QLatin1String()
1503 \i Sets the encoding for a string to Latin-1, unless the string is
1504 already enclosed in QLatin1Char, QT_TRANSLATE_NOOP, tr, trUtf8,
1505 QLatin1Literal, or QLatin1String. For example, rewrites
1513 QLatin1String("abcd")
1519 \i Mark as Translatable
1520 \i Marks a string translatable. For example, rewrites \c "abcd" with
1521 one of the following options, depending on which of them is available:
1525 QCoreApplication::translate("CONTEXT", "abcd")
1526 QT_TRANSLATE_NOOP("GLOBAL", "abcd")
1532 \i #include Header File
1533 \i Adds the matching #include statement for a forward-declared class or struct
1534 \i Forward-declared class or struct
1536 \i Add Definition in 'filename'
1537 \i Inserts a definition stub for a member function declaration in the
1538 implementation file. The definition is placed after that of the
1539 preceding declaration. Qualified names are minimized when possible,
1540 instead of always being fully expanded.
1544 \i Add 'Function' Declaration
1545 \i Inserts the member function declaration that matches the member function
1546 definition into the class declaration. The function can be public,
1547 protected, private, public slot, protected slot, or private slot.
1550 \i Add Local Declaration
1552 Adds the type of an assignee, if the type of the right-hand side of the assignment
1553 is known. For example, rewrites
1565 where Type is the return type of \c {foo()}
1570 \i Convert to Camel Case
1571 \i Converts a symbol name to camel case, where elements of the name are joined
1572 without delimiter characters and the initial character of each element is
1573 capitalized. For example, rewrites \c an_example_symbol
1574 as \c anExampleSymbol and \c AN_EXAMPLE_SYMBOL as \c AnExampleSymbol
1577 \i Complete Switch Statement
1578 \i Adds all possible cases to a switch statement of the type \c enum
1581 \i Generate Missing Q_PROPERTY Members
1582 \i Adds missing members to a Q_PROPERTY:
1585 \o \c write method, if there is a WRITE
1586 \o \c {onChanged} signal, if there is a NOTIFY
1587 \o data member with the name \c {m_<propertyName>}
1592 \i Keeps function declarations and definitions synchronized by
1593 checking for the matching declaration or definition when you
1594 edit a function signature and by applying the changes to the
1596 \i Function signature. When this action is available, a light bulb
1598 \inlineimage qml-toolbar-indicator.png
1601 \section2 Refactoring QML Code
1603 You can apply the following types of refactoring actions to QML code:
1609 \o Split initializers
1611 \o Move a QML element into a separate file to reuse it in other
1616 The following table summarizes the refactoring actions for QML code. The
1617 action is available when the cursor is in the position described in the
1622 \i Refactoring Action
1627 \i Move Component into 'filename.qml'
1628 \i Moves a QML element into a separate file
1632 \i Renames all instances of an element ID in the currently open file
1635 \i Split Initializer
1636 \i Reformats a one-line element into a multi-line element. For example,
1640 Item { x: 10; y: 20; width: 10 }
1659 \contentspage index.html
1660 \previouspage qt-quick-toolbars.html
1661 \page creator-editor-locator.html
1662 \nextpage creator-editor-codepasting.html
1664 \title Searching With the Locator
1666 The locator provides one of the easiest ways in \QC to browse through
1667 projects, files, classes, methods, documentation and file systems. You can
1668 find the locator in the bottom left of the \QC window.
1670 To activate the locator, press \key Ctrl+K (\key Cmd+K on Mac OS X) or
1671 select \gui Tools > \gui Locate.
1673 \image qtcreator-locator.png
1675 To edit the currently open project's main.cpp file using the locator:
1679 \o Activate the locator by pressing \key Ctrl+K.
1681 \o Enter \tt{main.cpp}.
1683 \image qtcreator-locator-open.png
1685 \o Press \key Return.
1687 The main.cpp file opens in the editor.
1691 It is also possible to enter only a part of a search string. As you type,
1692 the locator shows the occurrences of that string regardless of where in the
1693 name of an component it appears.
1695 To narrow down the search results, you can use the following wildcard
1700 \o To match any number of any or no characters, enter \bold{*}.
1702 \o To match a single instance of any character, enter \bold{?}.
1706 \section1 Using the Locator Filters
1708 The locator allows you to browse not only files, but any items defined by
1709 \bold{locator filters}. By default, the locator contains filters for:
1713 \o Locating any open document
1715 \o Locating files anywhere on your file system
1717 \o Locating iles belonging to your project, such as source, header
1718 resource, and .ui files
1720 \o Locating class and method definitions in your project or anywhere
1721 referenced from your project
1723 \o Locating class and method definitions in the current document
1725 \o Locating a specific line in the document displayed in your editor
1727 \o Opening help topics, including Qt documentation
1729 \o Performing web searches
1731 \o Running text editing macros that you record and save. For more
1732 information, see \l{Using Text Editing Macros}
1736 To use a specific locator filter, type the assigned prefix followed by
1737 \key Space. The prefix is usually a single character.
1739 For example, to locate symbols matching QDataStream:
1743 \o Activate the locator.
1745 \o Enter \tt{\bold{: QDataStream}} (: (colon) followed by a
1746 \key Space and the symbol name (QDataStream)).
1748 The locator lists the results.
1750 \image qtcreator-navigate-popup.png
1754 By default, the following filters are enabled and you do not need to use
1755 their prefixes explicitly:
1759 \o Going to a line in the current file (l).
1761 \o Going to an open file (o).
1763 \o Going to a file in any open project (a).
1767 \section2 Using the Default Locator Filters
1769 The following locator filters are available by default:
1777 \o Go to a line in the current file.
1778 \o \tt{\bold{l \e{Line number}}}
1779 \o \image qtcreator-locator-line.png
1781 \o Go to a symbol definition.
1782 \o \tt{\bold{: \e{Symbol name}}}
1783 \o \image qtcreator-locator-symbols.png
1785 \o Go to a symbol definition in the current file.
1786 \o \tt{\bold{. \e{Symbol name}}}
1787 \o \image qtcreator-locator-method-list.png
1789 \o Go to a help topic.
1790 \o \tt{\bold{? \e{Help topic}}}
1791 \o \image qtcreator-locator-help.png
1793 \o Search for a term by using a web search engine.
1794 \o \tt{\bold{r \e{Search term}}}
1795 \o \image qtcreator-locator-web.png
1797 \o Go to an open file.
1798 \o \tt{\bold{o \e{File name}}}
1799 \o \image qtcreator-locator-opendocs.png
1801 \o Go to a file in the file system (browse the file system).
1802 \o \tt{\bold{f \e{File name}}}
1803 \o \image qtcreator-locator-filesystem.png
1805 \o Go to a file in any project currently open.
1806 \o \tt{\bold{a \e{File name}}}
1807 \o \image qtcreator-locator-files.png
1809 \o Go to a file in the current project.
1810 \o \tt{\bold{p \e{File name}}}
1811 \o \image qtcreator-locator-current-project.png
1813 \o Go to a class definition.
1814 \o \tt{\bold{c \e{Class name}}}
1815 \o \image qtcreator-locator-classes.png
1817 \o Go to a method definition.
1818 \o \tt{\bold{m \e{Method name}}}
1819 \o \image qtcreator-locator-methods.png
1821 \o Execute a text editing macro.
1822 \o \tt{\bold{rm \e{Macro name}}}
1823 \o \image qtcreator-locator-macros.png
1826 \section2 Creating Locator Filters
1828 To quickly access files not directly mentioned in your project, you can
1829 create your own locator filters. That way you can locate files in a
1830 directory structure you have defined.
1832 To create a locator filter:
1836 \o In the locator, click \inlineimage qtcreator-locator-magnify.png
1837 and select \gui Configure. to open the \gui Locator options.
1839 \image qtcreator-locator-customize.png
1843 \o In the \gui{Filter Configuration} dialog:
1847 \o Name your filter.
1849 \o Select at least one directory. The locator searches directories
1852 \o Define the file pattern as a comma separated list. For example,
1853 to search all .h and .cpp files, enter \bold{*.h,*.cpp}
1855 \o Specify the prefix string.
1857 To show only results matching this filter, select
1858 \gui{Limit to prefix}.
1860 \image qtcreator-navigate-customfilter.png
1868 \section2 Adding Web Search Engines
1870 You can use the \gui {Web Search (\c r)} locator filter to perform
1871 web searches. URLs and search commands for Bing, Google, Yahoo! Search,
1872 cplusplus.com, and Wikipedia are configured by default.
1874 To find out the format of the search command to use for your favorite
1875 web search engine, perform a search in your browser and copy the resulting
1876 URL to the locator filter configuration. Replace the search term with the
1879 To add URLs and search commands to the list:
1883 \o Select \gui {Tools > Options > Locator > Web Search (prefix: r) >
1886 \o Select \gui Add to add a new entry to the list.
1888 \image qtcreator-add-online-doc.png "Filter Configuration dialog"
1890 \o Double-click the new entry to specify a URL and a search command.
1891 For example, http://www.google.com/search?q=%1.
1897 \section2 Configuring the Locator Cache
1899 The locator searches the files matching your file pattern in the
1900 directories you have selected and caches that information. The cache for
1901 all default filters is updated as you write your code. By default,
1902 \QC updates the filters created by you once an hour.
1904 To update the cached information manually, click
1905 \inlineimage qtcreator-locator-magnify.png
1906 and select \gui Refresh.
1908 To set a new cache update time:
1912 \o Select \gui Tools > \gui Options > \gui Locator.
1914 \o In \gui{Refresh interval}, define new time in minutes.