Qt Bridge for C# is a bridge between C# and QML, designed to write application logic in C# while using Qt Quick for the UI. The bridging mechanism is based on interoperability between C# and C++.
- Introduction
- Supported platforms
- Requirements
- Installing Qt Bridge
- Running examples
- Using dotnet CLI templates
- Using resources
- Troubleshooting
- What gets packaged
- Clean up
- Stay in touch
Qt Bridge for C# is intended for C# developers who want to experiment with Qt and/or QML without committing to a full C++ application. The repository includes example applications and dotnet CLI templates that demonstrate the recommended project structure, how to model data and logic in C#, and how to connect those models to QML views.
Detailed documentation can be found here.
The currently supported workflow is:
- Windows x64 with .NET 8+ using the bundled Qt runtime or an external Qt installation.
- Linux x64 with .NET 8+ using an external Qt installation from or compatible with the target Linux distribution.
- Windows 11 (
x64) or Ubuntu/WSL (x64) - .NET SDK 8+ (
dotnet --version) - Git
- CMake & Ninja
- A C++ toolchain:
- Windows: Visual Studio 2022 (Desktop development with C++) and x64 Native Tools Command Prompt
- Ubuntu/WSL:
build-essential(or equivalent)
- Python & Perl (required only if you build Qt from source); see Qt's system requirements
- Sufficient disk space (Qt build can require tens of GB)
System requirements reference: https://wiki.qt.io/Building_Qt_6_from_Git#System_Requirements
Qt Bridge is distributed as a NuGet package. You can add it to your project directly with a package reference, use the Visual Studio extension to create a preconfigured project, or build and consume local packages from this repository.
- In Visual Studio, select Project | Manage NuGet Packages....
- Select the Browse tab and enter QtGroup.Qt.Bridge.CSharp in the search field.
- Select the latest version from the Version dropdown and click Install.
Choose the package that matches your RID (runtime identifier). The Windows package includes a
minimal Qt runtime. The Linux package does not include Qt; set QtDir to a Qt 6 installation
prefix before building.
# Windows x64
dotnet add package QtGroup.Qt.Bridge.CSharp.win-x64 --version 0.3.*-*
# Linux x64 (Ubuntu / WSL)
dotnet add package QtGroup.Qt.Bridge.CSharp.linux-x64 --version 0.3.*-*Linux example:
dotnet build -p:QtDir=/usr/lib/qt6The selected Qt prefix must contain lib/cmake/Qt6/Qt6Config.cmake.
The Qt Bridge for C# Visual Studio extension is the recommended entry point for Visual Studio users. Installing the VSIX adds Qt Bridge project and item templates to Visual Studio, so you can create a Qt Bridge application without installing the dotnet templates separately.
The extension packages the Qt Bridge template package inside the VSIX. Projects created from the
extension template include the appropriate PackageReference to the Qt Bridge for C# NuGet package,
which gives you another way to get started with the bridge package besides adding the package
reference manually.
The extension also activates QML Language Server support for Qt Bridge projects. After a project is built, Visual Studio can use the generated Qt Bridge metadata to provide QML language features for the QML files in the project.
To use the extension:
- Install the
Qt.Bridge.CSharp.vsixpackage. - Restart Visual Studio if prompted.
- Create a new project using the Qt Bridge for C# project template, or add a QML file using the Qt Bridge item template.
- Build the project so the Qt Bridge package can restore and generate the metadata used by the QML Language Server integration.
The extension is Windows/Visual Studio-only. The dotnet CLI template workflow remains available for CLI users and for Linux/WSL development.
If you already have a Qt 6 installation that includes qtbase, qtsvg, qtshadertools,
qtdeclarative, qtquick3d, qtquick3dphysics, and qtquicktimeline, you can skip building Qt
from source. Set QtDir to the Qt installation prefix (the folder that contains bin, lib, and
include), then continue with Build the Qt Bridge for C#.
Windows (cmd / Native Tools Prompt):
set QtDir=D:\Qt\6.11.0\msvc2022_64Linux / WSL (bash):
export QtDir=~/work/qt6-installIf you already use the Qt QTDIR environment variable, MSBuild will also honor it because
environment variables are available as build properties.
The paths below use
D:\workfor demonstration. Adjust as needed. All commands are meant to run from the x64 Native Tools Command Prompt for VS 2022.
:: Choose a working directory
set WORKDIR=D:\work
pushd %WORKDIR%
:: Create Qt source/build/install folders
mkdir qt6-source
mkdir qt6-build
mkdir qt6-install
:: Clone Qt meta-repo (Qt 6 uses the qt5 meta-repo name)
git clone https://code.qt.io/qt/qt5.git qt6-source
:: Initialize only the modules we need
cd qt6-source
init-repository --module-subset=qtbase,qtsvg,qtshadertools,qtdeclarative,qtquick3d,qtquick3dphysics,qtquicktimeline
:: Configure out-of-source build
cd ..\qt6-build
..\qt6-source\configure -prefix ..\qt6-install -release -opensource -confirm-license -submodules qtbase,qtsvg,qtshadertools,qtdeclarative,qtquick3d,qtquick3dphysics,qtquicktimeline -- -DQT_BUILD_TESTS=OFF -DQT_BUILD_EXAMPLES=OFF
:: Build and install
cmake --build .
cmake --install .You can add
-DCMAKE_BUILD_PARALLEL_LEVEL=Nto speed up builds (or usecmake --build . --parallel). If you run into generator issues, you can specify-G "Ninja"and install Ninja. The above turns off Qt tests/examples to keep the build lean.
If you build on Ubuntu / WSL, install the .NET SDK first:
sudo apt-get update && sudo apt-get install -y dotnet-sdk-8.0-
Install required build dependencies
sudo apt update sudo apt install -y \ cmake ninja-build build-essential python3 pkg-config \ libegl-dev libgl-dev libglu1-mesa-dev mesa-common-dev \ libopengl-dev libglx-dev \ libx11-dev libx11-xcb-dev libxext-dev libxrender-dev libxi-dev \ libxcb1-dev libxcb-cursor-dev libxcb-glx0-dev libxcb-keysyms1-dev \ libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync-dev \ libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev \ libxcb-render-util0-dev libxcb-util-dev libxcb-xkb-dev \ libxkbcommon-dev libxkbcommon-x11-dev
-
Clone and initialize the required Qt modules
mkdir -p ~/work cd ~/work git clone https://code.qt.io/qt/qt5.git qt6-source cd qt6-source ./init-repository --module-subset=qtbase,qtsvg,qtshadertools,qtdeclarative,qtquick3d,qtquick3dphysics,qtquicktimeline
-
Configure an out-of-source build
cd ~/work mkdir -p qt6-build qt6-install cd qt6-build ../qt6-source/configure \ -prefix ../qt6-install \ -release \ -opensource \ -confirm-license \ -submodules qtbase,qtsvg,qtshadertools,qtdeclarative,qtquick3d,qtquick3dphysics,qtquicktimeline \ -- -DQT_BUILD_TESTS=OFF -DQT_BUILD_EXAMPLES=OFF
-
Build and install
cmake --build . --parallel cmake --install .
The resulting Qt installation is placed in ~/work/qt6-install and contains the usual bin,
lib, include, plugins, and qml directories.
If
configurefails with an OpenGL-related error, make sure the OpenGL and X11 / XCB development packages listed above are installed, then removeCMakeCache.txtandCMakeFiles/and runconfigureagain.
After Qt is available, run from this repository root:
dotnet build -c ReleaseOn Windows, setting QtInstallRoot before the build lets the local win-x64 package include the
Qt payload.
On Linux, the local linux-x64 package does not include Qt by default, even when QtInstallRoot
points to a valid Qt installation. Projects that consume the package must select a compatible
system Qt by setting QtDir.
To build a Linux package with a bundled Qt payload for local testing, opt in explicitly:
dotnet build -c Release \
-p:QtBridgePackBundledQt=true \
-p:QtInstallRoot=/path/to/qt- In Visual Studio, select Tools | Options | NuGet Package Manager | Package Sources.
- Add a source named, for example, Local Package Source with path
<repo-root>/nuget/local.
CLI alternative:
dotnet nuget add source ./nuget/local --name QtBridgeLocalAt this point, the Qt Bridge and Qt packages are ready, and any projects referencing Qt Bridge for C# can be built successfully.
The examples directory contains simple projects implemented with Qt Bridge for C#. For instance, to build and run the Primes test application:
# Build and run the test app (adjust the path if different)
dotnet build -c Release examples/Primes/Primes.csproj
dotnet run --project examples/Primes/Primes.csproj -c Releasewaylandis optional. If your Qt build/package does not include the Wayland platform plugin, startup can still work withxcb.- On Ubuntu/WSL, install runtime dependency:
sudo apt update
sudo apt install -y libxcb-cursor0- In WSL2, make sure GUI forwarding is available (WSLg / X server), then force
xcb:
QT_QPA_PLATFORM=xcb ./examples/Primes/bin/Release/net8.0/Primes- If startup reports
QFontDatabase: Cannot find font directory .../lib/fonts, the selected Qt installation does not provide bundled fonts for that system. Point Qt to a system font directory before launching the app, for example:
export QT_QPA_FONTDIR=/usr/share/fonts/truetype/ubuntu
QT_QPA_PLATFORM=xcb ./examples/Primes/bin/Release/net8.0/Primes- For headless validation only (no GUI):
QT_QPA_PLATFORM=offscreen ./examples/Primes/bin/Release/net8.0/PrimesThese templates are installed and used via the dotnet CLI (the dotnet command-line tool).
If you installed the Visual Studio extension, the Qt Bridge templates are already available in
Visual Studio. Install the dotnet templates separately only when you want to create Qt Bridge
projects or QML files from the dotnet CLI.
From a NuGet feed:
dotnet new install QtGroup.Qt.Bridge.CSharp.TemplatesFrom a local .nupkg:
dotnet new install ./nuget/local/QtGroup.Qt.Bridge.CSharp.Templates/<version>/QtGroup.Qt.Bridge.CSharp.Templates.<version>.nupkgVerify installation:
dotnet new listdotnet new qt -n MyQtApp
cd MyQtApp
dotnet build
dotnet runThe project template defaults to net8.0. To target a newer framework supported by your installed
.NET SDK, pass --Framework, for example:
dotnet new qt -n MyQtApp --Framework net9.0To include a small C# and QML counter sample in the generated project, pass --SampleCode:
dotnet new qt -n MyQtApp --SampleCodeThis generates:
MyQtApp/
Project.csproj
Program.cs
Main.qml
dotnet new qml -n MainPageThis creates MainPage.qml. The build integrates QML files automatically (they are registered and
copied alongside your app).
dotnet new uninstall QtGroup.Qt.Bridge.CSharp.TemplatesQt Bridge for C# packages app resources into the Qt Resource System. QML uses qrc:/ URLs
directly, and C# uses Qt.Resources when it needs to read the same packaged files.
See Resources in Qt Bridge for C# apps for the resource authoring model,
.resx integration, access modes, aliases, and cross-project resource usage.
- C++ toolchain not detected:
- Windows: use the x64 Native Tools prompt.
- Ubuntu/WSL: ensure
build-essential,cmake, andninja-buildare installed.
- Missing Python/Perl: Install them and ensure they are on
PATHbefore runninginit-repository/configure. - Rebuild Qt from scratch: Delete
qt6-buildandqt6-install, then runconfigureagain. - Linux/WSL runtime plugin errors:
- Install runtime dependency:
sudo apt install -y libxcb-cursor0 - Force
xcb:QT_QPA_PLATFORM=xcb ./examples/Primes/bin/Release/net8.0/Primes - Headless startup check:
QT_QPA_PLATFORM=offscreen ./examples/Primes/bin/Release/net8.0/Primes
- Install runtime dependency:
- Tests fail because the temp path contains spaces:
- The test harness requires a temp root without spaces.
- Set
QTBRIDGE_TEST_ROOTto a writable directory without spaces before running tests. - Windows:
set QTBRIDGE_TEST_ROOT=C:\temp - Ubuntu / WSL:
export QTBRIDGE_TEST_ROOT=/tmp
- WSL GUI: Make sure GUI forwarding is available (WSLg or X server).
The NuGet contains:
- .NET adapter (host Qt/QML engine from C#)
- Generator (discovers your types and emits interop glue)
- Filtering rules (Include/Ignore/Exclude attributes)
- C++ include headers for the native bridge
- On Windows packages, a minimal open-source Qt Quick runtime subset sufficient to run QML
Linux packages do not contain Qt. They use the Qt installation selected with QtDir.
To revert environment changes:
Windows:
set QtInstallRoot=
set QtDir=Ubuntu / WSL:
unset QtInstallRoot
unset QtDirYou can reach us on the Qt Forum, specifically in the Qt Bridges category.
Copyright (C) 2026 The Qt Company Ltd.
SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only
Qt Bridge for C# is available under the Qt Commercial License
or the GNU Lesser General Public License v3.0-only (LGPL-3.0-only).
For commercial licensing, see:
For LGPL-3.0-only, see:
This information does not replace the full license terms. Use is subject to the applicable license.
If you, your employer, or the legal entity you act on behalf of hold commercial license(s) with a Qt Group entity, Qt Bridges constitutes Pre-Release Code under the Qt License/Frame Agreement governing those licenses, and that agreement's terms and conditions relating to Pre-Release Code apply to your use of Qt Bridges as found in this repo. This Qt Bridges repo may provide links or access to third-party libraries or code (collectively "Third-Party Software") to implement various functions. Use or distribution of Third-Party Software is discretionary and in all respects subject to applicable license terms of applicable third-party right holders.
The Qt Bridge for C# is built using the .NET SDK and Runtime, which are developed and maintained by Microsoft and .NET Foundation
.NET and C# are trademarks of Microsoft Corporation. This project is not affiliated with, or endorsed by Microsoft.
The Qt Bridge for C# package includes the following modules in binary form, licensed under the MIT license:
- System.Reflection.MetadataLoadContext
- System.CommandLine
- System.IO.Hashing
If you contribute to the code of Qt Bridge for C#, you will additionally need the following packages licensed under the MIT license:
- Microsoft.NET.Test.Sdk
- MSTest.TestFramework
- Microsoft.CodeAnalysis.CSharp
- coverlet.collector