Refactoring

Refactor code to:

  • Improve internal quality of your application
  • Improve performance and extensibility
  • Improve code readability and maintainability
  • Simplify code structure

Finding QML Types

To find instances of a specific QML type in a project, place the cursor on the type and select Tools > QML/JS > Find References to Symbol Under Cursor or press Ctrl+Shift+U.

Viewing Search Results

Qt Design Studio searches from the following locations:

  • Files listed as a part of the project
  • Files directly used by the project files (for example, generated files)

The Search Results pane shows the location and number of search hits in the current project.

You can browse the search results in the following ways:

  • To go directly to an instance, double-click the instance in the Search Results pane.
  • To move between instances, click the (Next Item) button and (Previous Item) button in the Search Results pane.
  • To expand and collapse the list of all instances, click the (Expand All) button.
  • To clear the search results, click the (Clear) button.
  • To start a new search, click the (New Search) button.

Renaming Symbols

You can rename symbols in all files in a project. To rename a QML type in a project, select Tools > QML/JS > Rename Symbol Under Cursor or press Ctrl+Shift+R.

The Search Results pane shows the location and number of instances of the symbol in the current project.

To replace all selected instances, enter the name of the new symbol in the Replace with text box, and select Replace. To omit an instance, deselect the check box next to the instance.

Note: This action replaces all selected instances of the symbol in all files listed in the Search Results pane. You cannot undo this action.

Column Editing

To apply a change to several rows in a column simultaneously, hold Alt, select the rows using the mouse, and enter or remove text. The changes are made simultaneously at the cursor position on all the selected rows.

On Windows and Linux, you can also hold Alt+Shift and select the rows using the arrow keys and the PageUp, PageDown, Home, End keys.

Applying Refactoring Actions

Qt Design Studio 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.

To apply refactoring actions to QML code, right-click an item ID or name.

In the context menu, select Refactoring and then select a refactoring action.

You can also press Alt+Enter to open a context menu that contains refactoring actions available in the current cursor position.

Summary of Refactoring Actions

You can apply the following types of refactoring actions to QML code:

  • Rename IDs
  • Split initializers
  • Move a QML type into a separate file to reuse it in other .qml files

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.

Refactoring ActionDescriptionActivation
Move Component into Separate FileMoves a QML type into a separate file. Give the new component a name and select whether properties are set for the new component or for the original one.

QML type name. This action is also available in the Form Editor in the Design mode.
Split InitializerReformats a one-line type into a multi-line type. For example, rewrites
Item { x: 10; y: 20; width: 10 }

as

Item {
    x: 10;
    y: 20;
    width: 10
}
QML type property
Wrap Component in LoaderWraps the type in a Component type and loads it dynamically in a Loader type. This is usually done to improve startup time.QML type name
Add a message suppression commentPrepends the line with an annotation comment that stops the message from being generated.Error, warning or hint from static analysis

Available under certain Qt licenses.
Find out more.