Apply quick fixes

To apply quick fixes while refactoring code, select them in a context menu in the code editor. The fixes available depend on the position of the cursor in the code editor.

  1. To apply quick fixes:
    • In C++ code, right-click an operand, conditional statement, string, or name.
    • In QML code, right-click an item ID or name.
  2. In the context menu, go to Refactoring and then select a quick fix.

Or, press Alt+Enter to open a context menu that has quick fixes available in the current cursor position.

Create functions

Apply quick fixes to implement member functions, insert virtual functions of base classes, create getter and setter functions, and generate constructors. Specify settings for generating the functions either globally for all projects or separately for each project in the build and run settings of the project.

Implement member functions

Apply the Create Implementations for Member Functions quick fix to create implementations for all member functions in one go. In the Member Function Implementations dialog, specify whether the member functions are generated inline or outside the class.

"Implement Member Functions dialog"

Insert virtual functions

Apply the Insert Virtual Functions of Base Classes quick fix to insert declarations and the corresponding definitions inside or outside the class or in an implementation file (if it exists).

"Insert Virtual Functions dialog"

Select the functions to insert in the list of available functions. Filter the list and hide reimplemented functions from it.

You can add virtual or the override equivalent to the function declaration.

Create getters and setters

Apply the Create Getter and Setter Member Functions quick fix to create either both getter and setter member functions for member variables or only a getter or setter.

"Getters and Setters dialog"

Generate constructors

Apply the Generate Constructor quick fix to create a public, protected, or private constructor for a class. Select the class members to initialize in the constructor. Drag the parameters to specify their order in the constructor.

"Constructor dialog"

See also Specify settings for quick fixes, Quick Fixes, C++ Quick Fixes, QML Quick Fixes, and Refactoring.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.