- Qt Creator Documentation
- Use Qt AI Assistant
- Qt Creator 17.0.1

How To

# Use Qt AI Assistant

Qt AI Assistant is a coding assistant. When connected to a Large Language Model (LLM), it auto-completes your code, gives expert coding advice, suggests code fixes, as well as writes test cases and code documentation.

Qt AI Assistant is available for selected commercial Qt developer license holders. For more information on licensing, select Compare in Qt pricing.

Note: The LLM itself is not in scope of the Qt AI Assistant. You need to connect to a third-party LLM and agree to the terms and conditions, as well as to the acceptable use policy of the LLM provider. By using Qt AI Assistant, you agree to Terms & Conditions - Qt Development Framework.

Qt AI Assistant is currently experimental and powered by generative AI. Check all suggestions to make sure that they are fit for use in your project.

Note: Install and load the Qt AI Assistant extension to use it.

## Install Qt AI Assistant

To load the Qt AI Assistant extension from the web:

1. Go to Extensions.

2. Select Use external repository.
3. Select AI Assistant.
4. Select Install.

## Enable code syntax highlighting in the inline chat window

To enable code syntax highlighting in the inline chat window, go to Preferences > Text Editor > Generic Highlighter, and then select Download Definitions.

For more information, see Download highlight definitions.

## Install and use Ollama

To use LLMs running locally on your computer with the Qt AI Assistant extension, install Ollama. You can run models available from the Ollama selection as well as custom models that you add to Ollama.

### Run models on Ollama

To run models, enter:

     ollama run <model-name>

For example:

     ollama run codellama:7b-code

### Supported models from Ollama

You can use the following models directly from Ollama:

- `codellama:7b-code`
- `deepseek-coder-v2:lite`
- `theqtcompany/codellama-7b-qml`
- `theqtcompany/codellama-13b-qml`

### Custom models

For custom models, follow the specific installation instructions for that mode. You can use the following custom models:

- codellama:7b-code-qml
- codellama:13b-code-qml

## Connect to an LLM

You can connect to the following LLMs:

- Code Llama 13B QML (for Qt 6, running in a cloud deployment of your choice)
- Code Llama 13B (for Qt 5, running in a cloud deployment of your choice)
- Codestral (provided by Mistral)
- Llama 3.3 70B (running in a cloud deployment of your choice)
- Claude 3.7 Sonnet (provided by Anthropic, remember that you need to have a token-based billing payment method configured for your Anthropic account: console.anthropic.com)
- GPT 4o (provided by OpenAI, remember that you need to have a token-based billing payment method configured for your OpenAI account: platform.openai.com)
- GPT 4.1-mini (provided by OpenAI)
- DeepSeek V3 (provided by DeepSeek)
- Code Llama 13B QML through Ollama (running locally on your computer)
- Code Llama 7B QML through Ollama (running locally on your computer)
- Code Llama 7B through Ollama (running locally on your computer)
- DeepSeek Coder V2 Lite through Ollama (running locally on your computer)

To connect to an LLM:

1. Go to Preferences > AI Assistant > General.

2. Select an LLM for each configurable use case.
3. Go to Advanced.

4. Enter the API authentication token and server URL of each LLM. For more information on where to get the access information, see the third-party LLM provider documentation.

## Automatic code-completion

Qt AI Assistant can help you write code by suggesting what to write next. It prompts the LLM to make one code suggestion when you stop typing.

To accept the entire suggestion, select the Tab key.

To accept parts of the suggestions, select Alt+Right.

To dismiss the suggestion, select Esc or navigate to another position in the code editor.

To interact with Qt AI Assistant using the mouse, hover over the suggestion.

When you hover over a suggestion, you can accept parts of the suggested code snippet word-by-word or line-by-line.

To close the code completion bar, select the Esc key or move the cursor to another position.

To select the model for code completion, go to Preferences > AI Assistant > General.

In General, you can also turn auto-completion of code on or off globally for all projects. Qt AI Assistant consumes a significant number of tokens from the LLM. To cut costs, turn off the auto-completion feature when not needed, and use keyboard shortcuts for code completion.

## Complete code from the keyboard

To trigger code suggestions manually, select Ctrl+'.

## Enter prompts and smart commands

In an inline prompt window in the text editor, you can prompt the assistant to implement your requests in human language, ask questions, or execute smart commands. To open the chat, select Ctrl+Shift+A. Alternatively, to open the inline prompt window, you can select code and then select .

To close the inline prompt window, select Esc or .

To go to Qt AI Assistant preferences from the inline prompt window, select . There, you can set the model to use for prompts and code reviews.

### Request suggestions using human language

To request suggestions using human language, enter your requests into the input field. If you have highlighted code, the AI assistant adds it as context to the prompt. Qt AI Assistant shows a suggestion that you can copy to the clipboard by selecting Copy in the inline prompt window.

### Request code review

To review code with Qt AI Assistant:

1. Highlight code in the code editor.
2. Open the inline prompt window.
3. Select the /review smart command.

Qt AI Assistant reviews the code and suggests improvements. It uses QML Lint to review QML code if Enable QML linter is on in Preferences > AI Assistant > General.

### Request test cases in Qt Test syntax

To write test cases with Qt AI Assistant:

1. Highlight code in the code editor.
2. Open the inline prompt window.
3. Select the /qtest smart command.

Qt AI Assistant generates a test case in Qt Test format that you can copy and paste to your Qt test project.

### Request code documentation in Markdown format

To create code documentation:

1. Highlight code in the code editor.
2. Open the inline prompt window.
3. Select the /doc smart command.

Qt AI Assistant generates code documentation in a format that you can copy and paste to your documentation file.

### Request fixing of code

To request a fix to your code:

1. Highlight code in the code editor.
2. Open the inline prompt window.
3. Select the /fix smart command.
4. Optionally, apply the changes to the code.

Qt AI Assistant suggests a fix that you can apply to your code.

### Request explaining of code

To request an explanation of existing code:

1. Highlight code in the code editor.
2. Open the inline prompt window.
3. Select the /explain smart command.

Qt AI Assistant provides an explanation of the highlighted code.

### Add inline comments

To add inline comments to existing code with Qt AI Assistant:

1. Highlight code in the code editor.
2. Open the inline prompt window.
3. Select the /inlinecomments smart command.
4. Optionally, apply the comments to your code.

Qt AI Assistant adds inline comments that you can apply to your code.

See also Install extensions and Load extensions.