Code Languages | Qt

# Code Languages

## Code blocks

Code is marked up as C++ by default:

    // Some C++ code:
    QWidget *widget = getWidget();

Code can be explicitly marked up as C++ with the `Cpp` language:

    // Some C++ code:
    QWidget *widget = getWidget();

QML code can be requested with the `QML` language:

    // Some QML code:
    Item {
        id: my_item
    }

Plain text is shown if the `text` language is used:

    // Some C++ code:
    QWidget *widget = getWidget();

    // Some QML code:
    Item {
        id: my_item
    }

The case of the specified language is not important:

    // Some C++ code:
    QWidget *widget = getWidget();

Languages that QDoc does not handle are accepted but not processed if the language was declared in the `languages` configuration variable:

    def fn():
        pass

A warning will be generated if the language is unknown and not listed in the `languages` configuration variable:

    10 PRINT "Hello world!"
    20 GOTO 10

## Snippets

By default, code snippets use the appropriate language for the file that contains them, such as with this C++ code:

    int sum(int v0, int v1)
    {
       return v0 + v1;
    }

The language can be specified to override the language associated with the file name; for example, with `text` to obtain unmarked text:

    int sum(int v0, int v1)
    {
       return v0 + v1;
    }

As with code blocks, languages can be used that QDoc does not parse. Meta-data about the language is passed through to the output file:

    def fn(a, b):
        return a + b

This will only be styled correctly if a highlighter is used later in the publication process.

## Quoting whole files

Quoting a whole file using the `\\quotefile` command without a language argument relies on the use of the file name to determine the code marker:

    // Copyright (C) 2026 The Qt Company Ltd.
    // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

    int sum(int v0, int v1)
    {
       return v0 + v1;
    }

With a language argument, the code marker can be overridden:

    // Copyright (C) 2026 The Qt Company Ltd.
    // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

    int sum(int v0, int v1)
    {
       return v0 + v1;
    }

## Quoting parts of files

Using the `\\quotefromfile` command to quote parts of files without a language argument:

    int sum(int v0, int v1)
    {
       return v0 + v1;
    }

Parts of the file can be quoted with a different marker if the required language is passed as an argument to the `\\quotefromfile` command:

    int sum(int v0, int v1)
    {
       return v0 + v1;
    }