/**************************************************************************** ** ** Copyright (c) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of Qt Creator ** ** ** GNU Free Documentation License ** ** Alternatively, this file may be used under the terms of the GNU Free ** Documentation License version 1.3 as published by the Free Software ** Foundation and appearing in the file included in the packaging of this ** file. ** ** ****************************************************************************/ // ********************************************************************** // NOTE: the sections are not ordered by their logical order to avoid // reshuffling the file each time the index order changes (i.e., often). // Run the fixnavi.pl script to adjust the links to the index order. // ********************************************************************** /*! \contentspage index.html \previouspage creator-coding-navigating.html \page creator-highlighting.html \nextpage creator-checking-code-syntax.html \title Semantic Highlighting \QC understands the C++, QML, and JavaScript languages as code, not as plain text. It reads the source code, analyzes it, and highlights it based on the semantic checks that it does for the following code elements: \list \o Types (such as classes, structs, and type definitions) \o Local variables \o Class fields \o Virtual methods \endlist To specify the color scheme to use for semantic highlighting, select \gui {Tools > Options > Text Editor > Fonts & Color}. \QC supports syntax highlighting also for other types of files than C++, QML, or JavaScript. \section1 Generic Highlighting Generic highlighting is based on highlight definition files that are provided by the \l{http://kate-editor.org/2005/03/24/writing-a-syntax-highlighting-file/} {Kate Editor}. You can download highlight definition files for use with \QC. For more information about the definition files, see \l{http://kde-files.org/index.php?xcontentmode=680}{KDE-Files.org}. If you have a Unix installation that comes with the Kate Editor, you might already have the definition files installed. Typically, the files are located in a read-only directory, and therefore, you cannot manage them. \QC can try to locate them and use them as fallback files, when the primary location does not contain the definition for the current file type. You can also specify the directory that contains preinstalled highlight definition files as the primary location. When you open a file for editing and the editor cannot find the highlight definition for it, an alert appears. You can turn off the alerts. You can also specify patterns for ignoring files. The editor will not alert you if highlight definitions for the ignored files are not found. To download highlight definition files: \list 1 \o Select \gui {Tools > Options > Text Editor > Generic Highlighter}. \image qtcreator-generic-highlighter.png "Generic Highlighter options" \o In the \gui Location field, specify the path to the primary location for highlight definition files. \o Click \gui {Download Definitions} to open a list of highlight definition files available for download. \image qtcreator-manage-definitions.png "Download Definitions dialog" \o Select highlight definition files in the list and click \gui {Download Selected Definitions}. \o Select the \gui {Use fallback location} check box to specify the secondary location where the editor will look for highlight definition files. \o Click \gui Autodetect to allow \QC to look for highlight definition files on your system, or click \gui Browse to locate them in the file system yourself. \o In the \gui {Ignored file patterns} field, specify file patterns. You will not receive alerts if the highlight definitions for the specified files are not found. \o Click \gui OK to save your changes. \endlist \section1 Highlighting and Folding Blocks Use block highlighting to visually separate parts of the code that belong together. For example, when you place the cursor within the braces, the code enclosed in braces is highlighted. \image qtcreator-blockhighlighting.png To enable block highlighting, select \gui Tools > \gui{Options} > \gui{Text Editor} > \gui Display > \gui{Highlight blocks}. Use the folding markers to collapse and expand blocks of code within braces. Click the folding marker to collapse or expand a block. In the figure above, the folding markers are located between the line number and the text pane. To show the folding markers, select \gui Tools > \gui{Options} > \gui{Text Editor} > \gui Display > \gui{Display folding markers}. This option is enabled by default. When the cursor is on a brace, the matching brace is animated by default. To turn off the animation and just highlight the block and the braces, select \gui {Tools > Options > Text Editor > Display} and deselect \gui {Animate matching parentheses}. */ /*! \contentspage index.html \previouspage creator-highlighting.html \page creator-checking-code-syntax.html \nextpage creator-completing-code.html \title Checking Code Syntax As you write code, \QC checks code syntax. When \QC spots a syntax error in your code it underlines it and shows error details when you move the mouse pointer over the error. Similarly, when you are working on an instance of a JavaScript object notation (JSON) entity, \QC underlines errors in JSON data structure. \list \o Syntax errors are underlined in red. In the following figure, a semicolon is missing at the end of the line. \image qtcreator-syntaxerror.png \o Semantic errors and warnings are underlined in olive. In the following figure, the variable is not used. \image qtcreator-semanticerror.png \endlist In addition, you can run static checks on the QML and JavaScript code in your project to find common problems. \section1 Checking JSON Data Structure \QC validates instances of JSON entities against \l{http://tools.ietf.org/html/draft-zyp-json-schema-03} {A JSON Media Type for Describing the Structure and Meaning of JSON Documents}. However, this feature is still under development, and \QC does not yet understand the entire specification. A JSON schema defines the structure of JSON data. It determines what JSON data is required for an application and how to interact with it. The specification does not define how to map JSON instances with JSON schemas. As a temporary solution, \QC looks for a JSON schema file with a name that matches the name of the JSON instance file in the user configuration folder. For example, \c {~/config/QtProject/qtcreator/json} on Linux and Mac OS and \c {C:\Users\username\AppData\Roaming\QtCreator\qtcreator\json} in Windows. To check JSON data structure, copy the JSON schema file to the above folder. \section1 Checking JavaScript and QML Syntax To run the checks, select \gui {Tools > QML/JS > Run Checks} or press \key Ctrl+Shift+C. The results are shown in the \gui {QML Analysis} filter of the \gui {Issues} output pane. \section1 List of JavaScript and QML Checks Many of the JavaScript checks are similar to the ones in Douglas Crockford's JSLint tool and are explained well on \l{http://www.jslint.com/lint.html}{the JSLint website}. \table \header \o Id \o Severity \o Message \o Description \row \o M1 \o Error \o Invalid value for enum \o \row \o M2 \o Error \o Enum value must be a string or a number \o \row \o M3 \o Error \o Number value expected \o \row \o M4 \o Error \o Boolean value expected \o \row \o M5 \o Error \o String value expected \o \row \o M6 \o Error \o Invalid URL \o \row \o M7 \o Warning \o File or directory does not exist \o \row \o M8 \o Error \o Invalid color \o \row \o M9 \o Error \o Anchor line expected \o \row \o M10 \o Error \o Duplicate property binding \o \row \o M11 \o Error \o Id expected \o \row \o M14 \o Error \o Invalid id \o \row \o M15 \o Error \o Duplicate id \o Ids in a file must be unique. \row \o M16 \o Error \o Invalid property name 'name' \o \row \o M17 \o Error \o 'Name' does not have members \o \row \o M18 \o Error \o 'Field' is not a member of 'object' \o \row \o M19 \o Warning \o Assignment in condition \o It could be a typing error. If it is intentional, wrap the assignment in parentheses. \row \o M20 \o Warning \o Unterminated non-empty case block \o Case blocks should either be empty or end in a flow control statement such as 'break', 'return' or 'continue'. Alternatively you can indicate intentional fall through by ending with a '// fall through' comment. \row \o M23 \o Warning \o Do not use 'eval' \o \row \o M28 \o Warning \o Unreachable \o Indicates that the underlined statement will never be executed. \row \o M29 \o Warning \o Do not use 'with' \o \row \o M30 \o Warning \o Do not use comma expressions \o \row \o M31 \o Warning \o Unnecessary message suppression \o \row \o M103 \o Warning \o 'Name' is already a formal parameter \o \row \o M104 \o Warning \o 'Name' is already a function \o \row \o M105 \o Warning \o Var 'name' is used before its declaration \o \row \o M106 \o Warning \o 'Name' is already a var \o \row \o M107 \o Warning \o 'Name' is declared more than once \o Variables declared in a function are always visible everywhere in the function, even when declared in nested blocks or 'for' statement conditions. Redeclaring a variable has no effect. \row \o M108 \o Warning \o Function 'name' is used before its declaration \o \row \o M109 \o Warning \o Do not use 'Boolean' as a constructor \o \row \o M110 \o Warning \o Do not use 'String' as a constructor \o \row \o M111 \o Warning \o Do not use 'Object' as a constructor \o \row \o M112 \o Warning \o Do not use 'Array' as a constructor \o \row \o M113 \o Warning \o Do not use 'Function' as a constructor \o \row \o M114 \o Hint \o The 'function' keyword and the opening parenthesis should be separated by a single space \o \row \o M115 \o Warning \o Do not use stand-alone blocks \o Blocks do not affect variable scoping. Thus blocks that are not associated to 'if', 'while', etc. have no effect and should be avoided. \row \o M116 \o Warning \o Do not use void expressions \o \row \o M117 \o Warning \o Confusing pluses \o \row \o M119 \o Warning \o Confusing minuses \o \row \o M121 \o Hint \o Declare all function vars on a single line \o \row \o M123 \o Hint \o Unnecessary parentheses \o \row \o M126 \o Warning \o == and != may perform type coercion, use === or !== to avoid \o The non-strict equality comparison is allowed to convert its arguments to a common type. That can lead to unexpected results such as \c {' \t\r\n' == 0} being true. Prefer to use the strict equality operators === and !== and be explicit about conversions you require. \row \o M305 \o Warning \o == and != perform type coercion, use === or !== to avoid \o (see above) \row \o M127 \o Warning \o Expression statements should be assignments, calls or delete expressions only \o \row \o M201 \o Hint \o Var declarations should be at the start of a function \o \row \o M202 \o Hint \o Only use one statement per line \o \row \o M300 \o Error \o Unknown component \o \row \o M301 \o Error \o Could not resolve the prototype 'name' of 'object' \o \row \o M302 \o Error \o Could not resolve the prototype 'name' \o \row \o M303 \o Error \o Prototype cycle, the last non-repeated component is 'name' \o \row \o M304 \o Error \o Invalid property type 'name' \o \row \o M306 \o Warning \o Calls of functions that start with an uppercase letter should use 'new' \o By convention, functions that start with an uppercase letter are constructor functions that should only be used with 'new'. \row \o M307 \o Warning \o 'new' should only be used with functions that start with an uppercase letter \o \row \o M308 \o Warning \o Do not use 'Number' as a constructor \o \row \o M309 \o Hint \o Use spaces around binary operators \o \row \o M310 \o Warning \o Unintentional empty block, use ({}) for empty object literal \o \row \o M311 \o Hint \o Use 'type' instead of 'var' or 'variant' to improve performance \o \endtable */ /*! \contentspage index.html \previouspage creator-checking-code-syntax.html \page creator-completing-code.html \nextpage creator-indenting-code.html \title Completing Code As you write code, \QC suggests properties, IDs, and code snippets to complete the code. It provides a list of context-sensitive suggestions to the statement currently under your cursor. Press \key Tab or \key Enter to accept the selected suggestion and complete the code. \image qtcreator-codecompletion.png To open the list of suggestions at any time, press \key{Ctrl+Space}. If only one option is available, \QC inserts it automatically. When completion is invoked manually, \QC completes the common prefix of the list of suggestions. This is especially useful for classes with several similarly named members. To disable this functionality, uncheck \gui{Autocomplete common prefix} in the code completion preferences. Select \gui Tools > \gui{Options} > \gui{Text Editor} > \gui Completion. By default, code completion considers only the first letter case-sensitive. To apply full or no case-sensitivity, select the option in the \gui {Case-sensitivity} field. \section2 Summary of Available Types The following table lists available types for code completion and icon used for each. \table \header \o Icon \o Description \row \o \inlineimage completion/class.png \o A class \row \o \inlineimage completion/enum.png \o An enum \row \o \inlineimage completion/enumerator.png \o An enumerator (value of an enum) \row \o \inlineimage completion/func.png \o A function \row \o \inlineimage completion/func_priv.png \o A private function \row \o \inlineimage completion/func_prot.png \o A protected function \row \o \inlineimage completion/var.png \o A variable \row \o \inlineimage completion/var_priv.png \o A private variable \row \o \inlineimage completion/var_prot.png \o A protected variable \row \o \inlineimage completion/signal.png \o A signal \row \o \inlineimage completion/slot.png \o A slot \row \o \inlineimage completion/slot_priv.png \o A private slot \row \o \inlineimage completion/slot_prot.png \o A protected slot \row \o \inlineimage completion/keyword.png \o A C++ keyword \row \o \inlineimage completion/snippet.png \o A C++ code snippet \row \o \inlineimage completion/element.png \o A QML element \row \o \inlineimage completion/qmlsnippet.png \o A QML code snippet \row \o \inlineimage completion/macro.png \o A macro \row \o \inlineimage completion/namespace.png \o A namespace \endtable \section2 Completing Code Snippets Code snippets can consist of multiple variables that you specify values for. Select an item in the list and press \key Tab or \key Enter to complete the code. Press \key Tab to move between the variables and specify values for them. When you specify a value for a variable, all instances of the variable within the snippet are renamed. \image qmldesigner-code-completion.png "Completing QML code" \section2 Editing Code Snippets Code snippets specify C++ or QML code constructs. You can add, modify, and remove snippets in the snippet editor. To open the editor, select \gui {Tools > Options > Text Editor > Snippets}. \image qtcreator-edit-code-snippets.png "Snippet options" \QC provides you with built-in snippets in the following categories: \list \o Text snippets, which can contain any text string. For example, code comments \o C++ code snippets, which specify C++ code constructs \o QML code snippets, which specify QML code constructs \endlist \section3 Adding and Editing Snippets Select a snippet in the list to edit it in the snippet editor. To add a new snippet, select \gui Add. Specify a trigger and, if the trigger is already in use, an optional variant, which appear in the list of suggestions when you write code. Also specify a text string or C++ or QML code construct in the snippet editor, depending on the snippet category. The snippet editor provides you with: \list \o Highlighting \o Indentation \o Parentheses matching \o Basic code completion \endlist Specify the variables for the snippets in the following format: \c $variable$ Use unique variable names within a snippet, because all instances of a variable are renamed when you specify a value for it. The snippet editor does not check the syntax of the snippets that you edit or add. However, when you use the snippets, the code editor marks any errors by underlining them in red. To discard the changes you made to a built-in snippet, select \gui {Revert Built-in}. \section3 Removing Snippets Several similar built-in snippets might be provided for different use cases. To make the list of suggestions shorter when you write code, remove the built-in snippets that you do not need. If you need them later, you can restore them. To remove snippets, select a snippet in the list, and then select \gui Remove. To restore the removed snippets, select \gui {Restore Removed Built-ins}. \section3 Resetting Snippets To remove all added snippets and to restore all removed snippets, select \gui {Reset All}. \note If you now select \gui OK or \gui Apply, you permanently lose all your own snippets. */ /*! \contentspage index.html \previouspage qt-quick-toolbars.html \page creator-editor-codepasting.html \nextpage creator-macros.html \title Pasting and Fetching Code Snippets In \QC, you can paste snippets of code to a server or fetch snippets of code from the server. To paste and fetch snippets of code, \QC uses the following: \list \o \gui{CodePaster} \o \gui{Pastebin.Com} \o \gui{Pastebin.Ca} \o \gui{Paste.KDE.Org} \o \gui{Shared network drives} \endlist To configure the server, select \gui{Tools} > \gui{Options} > \gui{Code Pasting}. In \gui CodePaster, specify the host name of the CodePaster service. In \gui Fileshare, specify the path to a shared network drive. The code snippets are copied to the drive as simple files. You have to delete obsolete files from the drive manually. To paste a snippet of code onto the server, select \gui{Tools} > \gui{Code Pasting} > \gui{Paste Snippet} or press \key{Alt+C,Alt+P}. By default, \QC copies the URL of the snippet to the clipboard and displays the URL in the \gui Output pane. To fetch a snippet of code from the server, select \gui{Tools} > \gui{Code Pasting} > \gui{Fetch Snippet} or press \key{Alt+C,Alt+F}. \note To use \gui{Pastebin.Com}, configure the domain prefix in \gui{Tools} > \gui{Options} > \gui{Code Pasting} > \gui{Pastebin.com}. For example, you might ask colleagues to review a change that you plan to submit to a version control system. If you use the Git version control system, you can create a \e{diff} view by selecting \gui{Tools > Git > Diff Repository}. You can then upload its contents to the server by choosing \gui{Tools} > \gui{Code Pasting} > \gui{Paste Snippet}. The reviewers can retrieve the code snippet by selecting \gui{Tools > Code Pasting > Fetch Snippet}. If they have the project currently opened in \QC, they can apply and test the change by choosing \gui{Tools > Git > Apply Patch}. */ /*! \contentspage index.html \previouspage creator-editor-codepasting.html \page creator-macros.html \nextpage creator-finding-overview.html \title Using Text Editing Macros To record a text editing macro, select \gui {Tools > Macros > Record Macro} or press \key {Alt+(}. To stop recording, select \gui {Tools > Macros > Stop Recording Macro} or press \key {Alt+)}. To play the last macro, select \gui {Tools > Macros > Play Last Macro} or press \key {Alt+R}. To save the last macro, select \gui {Tools > Macros > Save Last Macro}. To assign a keyboard shortcut to a text editing macro, select \gui {Tools > Options > Environment > Keyboard}. For more information, see \l{Configuring Keyboard Shortcuts}. You can also use the \c rm locator filter to run a macro. For more information, see \l{Searching with the Locator}. To view and remove saved macros, select \gui {Tools > Options > Text Editor > Macros}. */ /*! \contentspage index.html \previouspage creator-editor-options-text.html \page creator-editor-fakevim.html \nextpage creator-mime-types.html \title Using FakeVim Mode In the \gui{FakeVim} mode, you can run the main editor in a manner similar to the Vim editor. To run the editor in the \gui{FakeVim} mode, select \gui{Edit} > \gui{Advanced} > \gui{Use Vim-style Editing} or press \key{Alt+V,Alt+V}. In the \gui{FakeVim} mode, most keystrokes in the main editor will be intercepted and interpreted in a way that resembles Vim. Documentation for Vim is not included in \QC. For more information on using Vim, see \l{http://www.vim.org/docs.php}{Documentation} on the Vim web site. To map commands entered on the \gui{FakeVim} command line to actions of the \QC core, select \gui{Tools} > \gui{Options} > \gui{FakeVim} > \gui{Ex Command Mapping}. To map \e {user commands} to keyboard shortcuts, select \gui{Tools > Options > FakeVim > User Command Mapping}. The user command mapped to the shortcut is executed by FakeVim as if you were typing it (as when replaying a macro). To make changes to the Vim-style settings, select \gui{Tools} > \gui{Options} > \gui FakeVim > \gui{General}. \image qtcreator-fakevim-options.png "FakeVim options" To preselect the indentation settings specified for the text editor, select \gui {Copy Text Editor Settings}. To preselect the Qt coding style, select \gui {Set Qt Style}. To preselect a simple indentation style, select \gui {Set Plain Style}. You can then change any of the preselected settings. To use a Vim-style color scheme, select \gui {Tools > Options > Text Editor > Fonts & Color}. In the \gui {Color Scheme} list, select \gui {Vim (dark)}. To quit the FakeVim mode, unselect \gui{Tools} > \gui{Options} > \gui{FakeVim} > \gui {Use FakeVim} or press \key{Alt+V,Alt+V}. You can temporarily escape FakeVim mode to access the normal \QC keyboard shortcuts like \key{Ctrl-R} for \gui{Run} by pressing \key{,} first. */ /*! \contentspage index.html \previouspage creator-completing-code.html \page creator-indenting-code.html \nextpage qt-quick-toolbars.html \title Indenting Code When you type code, it is indented automatically according to the selected text editor and code style options. Select a block to indent it when you press \key Tab. Press \key {Shift+Tab} to decrease the indentation. You can disable automatic indentation. You can specify indentation either globally for all files or separately for: \list \o Text files \o C++ files \o QML files \endlist You can also specify indentation separately for each project. You can specify several sets of code style settings and easily switch between them. In addition, you can import and export code style settings. \section1 Indenting Text Files To specify global indentation settings for the text editor, select \gui {Tools > Options > Text Editor > Behavior}. You can also use these settings globally for all editors and files. \image qtcreator-indentation.png "Text Editor Behavior options" To specify settings for a particular project, select \gui {Projects > Editor Settings}. You can specify how to interpret the \key Tab and \key Backspace key presses and how to align continuation lines. \section1 Indenting C++ Files To specify indentation settings for the C++ editor: \list 1 \o Select \gui {Tools > Options > C++}. \o In the \gui {Current settings} field, select the settings to modify and click \gui Copy. \image qtcreator-options-code-style-cpp.png "C++ Code Style options" \o Give a name to the settings and click \gui OK. \o Click \gui Edit to specify code style settings for the project. \image qtcreator-code-style-settings-edit-cpp.png "Edit Code Style Settings dialog" \endlist You can specify how to: \list \o Interpret the \key Tab and \key Backspace key presses. \o Indent the contents of classes, methods, blocks, and namespaces. \o Indent braces in classes, namespaces, enums, methods, and blocks. \o Control switch statements and their contents. \o Align continuation lines. \endlist You can use the live preview to see how the options change the indentation. To specify the settings for a particular project, select \gui {Projects > Code Style Settings}. \section1 Indenting QML Files To specify global settings for the Qt Quick editor: \list 1 \o Select \gui {Tools > Options >Qt Quick}. \o In the \gui {Current settings} field, select the settings to modify and click \gui Copy. \image qtcreator-options-code-style-qml.png "QML Code Style options" \o Give a name to the settings and click \gui OK. \o Click \gui Edit to specify code style settings for the project. \image qtcreator-code-style-settings-edit-qtquick.png "Edit Code Style Settings dialog" \endlist You can specify how to interpret the \key Tab key presses and how to align continuation lines. To specify the settings for a particular project, select \gui {Projects > Code Style Settings}. \section1 Specifying Tab Settings You can specify tab settings at the following levels: \list \o Global settings for all files \o Global C++ settings for C++ files \o Global Qt Quick settings for QML files \o Project specific settings for all editors of files in the project \o Project specific settings for C++ files in the project \o Project specific settings for QML files in the project \endlist \section2 Specifying Tabs and Indentation You can specify tab policy and tab size in the \gui Typing group. In the \gui {Tab policy} field, select whether to use only spaces or only tabs for indentation, or to use a mixture of them. By default, the tab length in code editor is 8 spaces and the indent size is 4 spaces. You can specify the tab length and indent size separately for each project and for different types of files. You can have continuation lines aligned with the previous line. In the \gui {Align continuation lines} field, select \gui {Not at all} to disable automatic alignment and indent continuation lines to the logical depth. To always use spaces for alignment, select \gui {With Spaces}. To follow the \gui {Tab policy}, select \gui {With Regular Indent}. \section2 Speficying Typing Options When you type code, it is indented automatically according to the selected text editor and code style options. Specify typing options in the \gui Typing group. To disable automatic indentation, deselect the \gui {Enable automatic indentation} check box. You can specify how the indentation is decreased when you press \gui Backspace in the \gui {Backspace indentation} field. To go back one space at a time, select \gui None. To decrease indentation in leading white space by one level, select \gui {Follows Previous Indents}. To move back one tab length if the character to the left of the cursor is a space, select \gui Unindents. You can specify whether the \key Tab key automatically indents text when you press it. To automatically indent text, select \gui Always in the \gui {Tab key performs auto-indent} field. To only indent text when the cursor is located within leading white space, select \gui {In Leading White Space}. \section1 Specifying Settings for Content You can indent public, protected, and private statements and declarations related to them within classes. You can also indent statements within methods and blocks and declarations within namespaces. \image qtcreator-code-style-content.png "Content options" \section1 Specifying Settings for Braces You can indent class, namespace, enum and method declarations and code blocks. \image qtcreator-code-style-braces.png "Braces options" \section1 Specifying Settings for Switch Statements You can indent case or default statements, or statements or blocks related to them within switch statements. \image qtcreator-code-style-switch.png "Switch options" \section1 Specifying Alignment To align continuation lines to tokens after assignments, such as = or +=, select the \gui {Align after assignments} check box. You can specify additional settings for aligning continuation lines in the \gui General tab. You can also add spaces to conditional statements, so that they are not aligned with the following line. Usually, this only affects \c if statements. \image qtcreator-code-style-alignment.png "Alignment options" */ /*! \contentspage index.html \previouspage creator-finding-overview.html \page creator-editor-finding.html \nextpage creator-editor-locator.html \title Finding and Replacing To search through the currently open file: \list 1 \o Press \key Ctrl+F or select \gui Edit > \gui Find/Replace > \gui{Find/Replace}. \o Enter the text you are looking for. If the text is found, all occurrences are highlighted as you type. \o To go to the next occurrence, click \inlineimage qtcreator-next.png (\gui {Find Next}), or press \key F3. To go to the previous occurrence click \inlineimage qtcreator-previous.png (\gui {Find Previous}), or press \key Shift+F3. \endlist You can restrict the search in the \gui Find field by selecting one or several search criteria: \list \o To make your search case sensitive, select \gui {Case Sensitive}. \o To search only whole words, select \gui {Whole Words Only}. \o To search using regular expressions, select \gui {Regular Expressions}. Regular expressions used in \QC are modeled on Perl regular expressions. For more information on using regular expressions, see \l {http://qt-project.org/doc/qt-4.8/qregexp.html#details} {Detailed Description} in the QRegExp Class Reference. \endlist \note If you have selected text before selecting \gui {Find/Replace}, the search is conducted within the selection. To replace occurrences of the existing text, enter the new text in the \gui{Replace with} field. \list \o To replace the selected occurrence and move to the next one, click \gui {Find Next} or press \key Ctrl+=. \o To replace the selected occurrence and move to the previous one, click \gui {Find Previous} . \o To replace all occurrences in the file, click \gui{Replace All}. \endlist \section1 Advanced Search To search through projects, files on a file system or the currently open file: \list 1 \o Press \key Ctrl+Shift+F or select \gui Edit > \gui Find/Replace > \gui{Advanced Find} > \gui{Open Advanced Find}. \o Select the scope of your search: \list \o \gui{All Projects} searches files matching the defined file pattern in all currently open projects. For example, to search for \tt previewer only in \tt .cpp and \tt .h files, enter in \gui{File pattern} \tt *.cpp,*.h. \image qtcreator-search-allprojects.png \o \gui{Current Project} searches files matching the defined file pattern only in the project you are currently editing. \o \gui{Files on File System} recursively searches files matching the defined file pattern in the selected directory. \o \gui{Current File} searches only the current file. \endlist \o Enter the text you are looking for and click \gui Search. \image qtcreator-searchresults.png A list of files containing the searched text is displayed in the \gui{Search Results} pane. \list \o To see all occurrences in a file, double-click the file name in the list. \o To go to an occurrence, double-click it. \o To repeat the search after you have made changes to the listed files, for example, select \gui {Search Again}. \endlist \endlist The search results are stored in the search history from which you can select earlier searches. \note You can use \gui{Advanced Find} also to search for symbols. For more information, see \l{Finding Symbols}. */ /*! \contentspage index.html \previouspage creator-editor-locator.html \page creator-editor-refactoring.html \nextpage creator-editor-options.html \title Refactoring Refactor code to: \list \o Improve internal quality of your application \o Improve performance and extensibility \o Improve code readability and maintainability \o Simplify code structure \endlist \section1 Finding Symbols To find the use of a specific symbol or \l{glossary-component} {QML component} in your Qt C++ or Qt Quick project: \list 1 \o In the editor, place the cursor on the symbol or component, and select: \list \o \gui {Tools > C++ > Find Usages} \o \gui {Tools > QML/JS > Find Usages} \o \key Ctrl+Shift+U \endlist \QC looks for the symbol in the following locations: \list \o Files listed as a part of the project \o Files directly used by the project files (for example, generated files) \o Header files of used frameworks and libraries \endlist \note You can also select \gui{Edit > Find/Replace > Advanced Find > C++ Symbols} to search for classes, methods, enums, and declarations either from files listed as part of the project or from all files that are used by the code, such as include files. \image qtcreator-search-cpp-symbols.png \o The \gui{Search Results} pane opens and shows the location and number of instances of the symbol in the current project. \image qtcreator-refactoring-find.png \endlist You can browse the search results in the following ways: \list \o To go directly to an instance, double-click the instance in the \gui{Search Results} pane. \o To move between instances, click \inlineimage qtcreator-forward.png and \inlineimage qtcreator-back.png in the \gui{Search Results} pane. \o To expand and collapse the list of all instances, click \inlineimage qtcreator-expand.png . \o To clear the search results, click \inlineimage qtcreator-clear.png . \endlist \section1 Renaming Symbols To rename a specific symbol in a Qt project: \list 1 \o In the editor, place the cursor on the symbol you would like to change and select \gui Tools > \gui C++ > \gui{Rename Symbol Under Cursor} or \gui Tools > \gui QML/JS > \gui{Rename Symbol Under Cursor}. Alternatively, press \key Ctrl+Shift+R. The \gui{Search Results} pane opens and shows the location and number of instances of the symbol in the current project. \image qtcreator-refactoring-replace.png \o To replace all selected instances, enter the name of the new symbol in the \gui{Replace with} text box and click \gui Replace. To omit an instance, uncheck the check-box next to the instance. \note This action replaces all selected instances of the symbol in all files listed in the \gui{Search Results} pane. You cannot undo this action. \endlist \note Renaming local symbols does not open the \gui{Search Results} pane. The instances of the symbol are highlighted in code and you can edit the symbol. All instances of the local symbol are changed as you type. \section1 Applying Refactoring Actions \QC allows you to quickly and conveniently apply actions to refactor your code by selecting them in a context menu. The actions available depend on the position of the cursor in the code editor and on whether you are writing C++ or QML code. To apply refactoring actions to C++ code, right-click an operand, conditional statement, string, or name to open a context menu. In QML code, click an element ID or name. In the context menu, select \gui {Refactoring} and then select a refactoring action. You can also press \gui {Alt+Enter} to open a context menu that contains refactoring actions available in the current cursor position. \section2 Refactoring C++ Code You can apply the following types of refactoring actions to C++ code: \list \o Change binary operands \o Simplify if and while conditions (for example, move declarations out of if conditions) \o Modify strings (for example, set the encoding for a string to Latin-1, mark strings translatable, and convert symbol names to camel case) \o Create variable declarations \o Create method declarations and definitions \endlist The following table summarizes the refactoring actions for C++ code. The action is available when the cursor is in the position described in the Activation column. \table \header \o Refactoring Action \o Description \o Activation \row \o Add Curly Braces \o Adds curly braces to an if statement that does not contain a compound statement. For example, rewrites \code if (a) b; \endcode as \code if (a) { b; } \endcode \o if \row \o Move Declaration out of Condition \o Moves a declaration out of an if or while condition to simplify the condition. For example, rewrites \code if (Type name = foo()) {} \endcode as \code Type name = foo; if (name) {} \endcode \o Name of the introduced variable \row \o Rewrite Condition Using || \o Rewrites the expression according to De Morgan's laws. For example, rewrites: \code !a && !b \endcode as \code !(a || b) \endcode \o && \row \o Rewrite Using \e operator \o Rewrites an expression negating it and using the inverse operator. For example, rewrites: \list \o \code a op b \endcode as \code !(a invop b) \endcode \o \code (a op b) \endcode as \code !(a invop b) \endcode \o \code !(a op b) \endcode as \code (a invob b) \endcode \endlist \o <= < > >= == != \row \o Split Declaration \o Splits a simple declaration into several declarations. For example, rewrites: \code int *a, b; \endcode as \code int *a; int b; \endcode \o Type name or variable name \row \o Split if Statement \o Splits an if statement into several statements. For example, rewrites: \code if (something && something_else) { } \endcode as \code if (something) { if (something_else) { } } \endcode and \code if (something || something_else) x; \endcode with \code if (something) x; else if (something_else) x; \endcode \o && || \row \o Swap Operands \o Rewrites an expression in the inverse order using the inverse operator. For example, rewrites: \code a op b \endcode as \code b flipop a \endcode \o <= < > >= == != && || \row \o Convert to Decimal \o Converts an integer literal to decimal representation \o Numeric literal \row \o Convert to Hexadecimal \o Converts an integer literal to hexadecimal representation \o Numeric literal \row \o Convert to Octal \o Converts an integer literal to octal representation \o Numeric literal \row \o Convert to Objective-C String Literal \o Converts a string literal to an Objective-C string literal if the file type is Objective-C(++). For example, rewrites the following strings \code "abcd" QLatin1String("abcd") QLatin1Literal("abcd") \endcode as \code @"abcd" \endcode \o String literal \row \o Enclose in QLatin1Char() \o Sets the encoding for a character to Latin-1, unless the character is already enclosed in QLatin1Char, QT_TRANSLATE_NOOP, tr, trUtf8, QLatin1Literal, or QLatin1String. For example, rewrites \code 'a' \endcode as \code QLatin1Char('a') \endcode \o String literal \row \o Enclose in QLatin1String() \o Sets the encoding for a string to Latin-1, unless the string is already enclosed in QLatin1Char, QT_TRANSLATE_NOOP, tr, trUtf8, QLatin1Literal, or QLatin1String. For example, rewrites \code "abcd" \endcode as \code QLatin1String("abcd") \endcode \o String literal \row \o Mark as Translatable \o Marks a string translatable. For example, rewrites \c "abcd" with one of the following options, depending on which of them is available: \code tr("abcd") QCoreApplication::translate("CONTEXT", "abcd") QT_TRANSLATE_NOOP("GLOBAL", "abcd") \endcode \o String literal \row \o #include Header File \o Adds the matching #include statement for a forward-declared class or struct \o Forward-declared class or struct \row \o Add Definition in 'filename' \o Inserts a definition stub for a member function declaration in the implementation file. The definition is placed after that of the preceding declaration. Qualified names are minimized when possible, instead of always being fully expanded. \o Method name \row \o Add 'Function' Declaration \o Inserts the member function declaration that matches the member function definition into the class declaration. The function can be public, protected, private, public slot, protected slot, or private slot. \o Method name \row \o Switch with Next/Previous Parameter \o Moves a parameter down or up one position in a parameter list. \o Parameter in the declaration or definition of a function or method \row \o Extract Method \o Moves the selected code to a new method and replaces the block of code with a call to the new method. Enter a name for the method in the \gui {Extract Function Refactoring} dialog. \o Block of code selected \row \o Add Local Declaration \i Adds the type of an assignee, if the type of the right-hand side of the assignment is known. For example, rewrites \code a = foo(); \endcode as \code Type a = foo(); \endcode where Type is the return type of \c {foo()} \o Assignee \row \o Convert to Camel Case \o Converts a symbol name to camel case, where elements of the name are joined without delimiter characters and the initial character of each element is capitalized. For example, rewrites \c an_example_symbol as \c anExampleSymbol and \c AN_EXAMPLE_SYMBOL as \c AnExampleSymbol \o Identifier \row \o Complete Switch Statement \o Adds all possible cases to a switch statement of the type \c enum \o Switch \row \o Generate Missing Q_PROPERTY Members \o Adds missing members to a Q_PROPERTY: \list \o \c read method \o \c write method, if there is a WRITE \o \c {onChanged} signal, if there is a NOTIFY \o data member with the name \c {m_} \endlist \o Q_PROPERTY \row \o Apply Changes \o Keeps function declarations and definitions synchronized by checking for the matching declaration or definition when you edit a function signature and by applying the changes to the matching code. \o Function signature. When this action is available, a light bulb icon appears: \inlineimage qml-toolbar-indicator.png \row \o Add #include for undeclared identifier \o Adds an #include directive to the current file to make the declaration of a symbol available. \o Undeclared identifier \endtable \section2 Refactoring QML Code You can apply the following types of refactoring actions to QML code: \list \o Rename IDs \o Split initializers \o Move a QML element into a separate file to reuse it in other .qml files \endlist The following table summarizes the refactoring actions for QML code. The action is available when the cursor is in the position described in the Activation column. \table \header \o Refactoring Action \o Description \o Activation \row \o Move Component into 'filename.qml' \o Moves a QML element into a separate file \o Element name \row \o Split Initializer \o Reformats a one-line element into a multi-line element. For example, rewrites \code Item { x: 10; y: 20; width: 10 } \endcode as \code Item { x: 10; y: 20; width: 10 } \endcode \o Element property \row \o Wrap in Loader \o Wraps the element in a Component element and loads it dynamically in a Loader element. This is usually done to improve startup time. \o Element name \row \o Add a message suppression comment \o Prepends the line with an annotation comment that stops the message from being generated. \o Error, warning or hint from static analysis \endtable */ /*! \contentspage index.html \previouspage creator-editor-finding.html \page creator-editor-locator.html \nextpage creator-editor-refactoring.html \title Searching with the Locator You can find the locator in the bottom left of the \QC window. To activate the locator, press \key Ctrl+K (\key Cmd+K on Mac OS X) or select \gui Tools > \gui Locate. \image qtcreator-locator.png To edit the currently open project's main.cpp file using the locator: \list 1 \o Activate the locator by pressing \key Ctrl+K. \o Enter \tt{main.cpp}. \image qtcreator-locator-open.png \o Press \key Enter. The main.cpp file opens in the editor. \o To move to a line in the file, enter the line number in the locator. \endlist To move directly to a particular line in the document when you open the document, append a plus sign (+) or a colon (:) to the file name in the locator. For example, to open main.cpp to line 41, enter: \c {main.cpp:41}. If the path to a file is very long, it might not fit into the locator window. To view the full path, press \key Alt when the filename is selected. It is also possible to enter only a part of a search string. As you type, the locator shows the occurrences of that string regardless of where in the name of an component it appears. To narrow down the search results, you can use the following wildcard characters: \list \o To match any number of any or no characters, enter \bold{*}. \o To match a single instance of any character, enter \bold{?}. \endlist \section1 Using Locator Filters The locator enables you to browse not only files, but any items defined by \bold{locator filters}. By default, the locator contains filters for: \list \o Locating any open document \o Locating files anywhere on your file system \o Locating files belonging to your project, such as source, header resource, and .ui files \o Locating class and method definitions in your project or anywhere referenced from your project \o Locating class and method definitions in the current document \o Locating a specific line in the document displayed in your editor \o Opening help topics, including Qt documentation \o Performing web searches \o Running text editing macros that you record and save. For more information, see \l{Using Text Editing Macros} \o Executing shell commands \o Executing version control system commands. For more information, see \l{Using Version Control Systems} \endlist To use a specific locator filter, type the assigned prefix followed by \key Space. The prefix is usually a single character. Then type the search string (typically, a filename or class name) or the command to execute. For example, to locate symbols matching QDataStream: \list 1 \o Activate the locator. \o Enter \tt{\bold{: QDataStream}} (: (colon) followed by a \key Space and the symbol name (QDataStream)). The locator lists the results. \image qtcreator-navigate-popup.png \endlist By default, the following filters are enabled and you do not need to use their prefixes explicitly: \list \o Going to a line in the current file (l). \o Going to an open file (o). \o Going to a file in any open project (a). \endlist \section1 Configuring Locator Filters If the default filters do not match your use case, you can check whether you can change them. For all filters, you can change the filter prefix and restrict the search to items that match the filter. To configure a locator filter: \list 1 \o In the locator, click \inlineimage qtcreator-locator-magnify.png (\gui {Options}) and select \gui Configure to open the \gui Locator options. \o Select a filter, and then select \gui Edit. \o Specify the prefix string. \o To show only results matching this filter, select \gui{Limit to prefix}. \o Specify other available options. For more information, see \l{Adding Web Search Engines}. \endlist \section2 Adding Web Search Engines You can use the \gui {Web Search (\c r)} locator filter to perform web searches. URLs and search commands for Bing, Google, Yahoo! Search, cplusplus.com, and Wikipedia are configured by default. To find out the format of the search command to use for your favorite web search engine, perform a search in your browser and copy the resulting URL to the locator filter configuration. Replace the search term with the variable \c {%1}. To add URLs and search commands to the list: \list 1 \o Select \gui {Tools > Options > Environment > Locator > Web Search (prefix: r) > Edit}. \o Select \gui Add to add a new entry to the list. \image qtcreator-add-online-doc.png "Filter Configuration dialog" \o Double-click the new entry to specify a URL and a search command. For example, http://www.google.com/search?q=%1. \o Click \gui OK. \endlist \section1 Creating Locator Filters To quickly access files not directly mentioned in your project, you can create your own locator filters. That way you can locate files in a directory structure you have defined. To create a locator filter: \list 1 \o In the locator, select \gui {Options > Configure} to open the \gui Locator options. \image qtcreator-locator-customize.png \o Click \gui Add. \o In the \gui{Filter Configuration} dialog: \list \o Name your filter. \o Select at least one directory. The locator searches directories recursively. \o Define the file pattern as a comma separated list. For example, to search all .h and .cpp files, enter \bold{*.h,*.cpp} \o Specify the prefix string. To show only results matching this filter, select \gui{Limit to prefix}. \image qtcreator-navigate-customfilter.png \endlist \o Click OK. \endlist \section1 Configuring Locator Cache The locator searches the files matching your file pattern in the directories you have selected and caches that information. The cache for all default filters is updated as you write your code. By default, \QC updates the filters created by you once an hour. To update the cached information manually, select \gui {Options > Refresh} in the locator. To set a new cache update time: \list 1 \o Select \gui {Tools > Options > Environment > Locator}. \o In \gui{Refresh interval}, define new time in minutes. \endlist */