Qt Bridges - Swift
Getting started
Qt Bridges allows writing QML applications with Swift without needing to write C++ code. It removes typical Qt boilerplate and provides a Swift-native feel.
Installation
Requirements
- macOS 15 or later
- Xcode 16 or later
- Swift 6.1 or later
Overview
Qt Bridges is distributed as Swift Package Manager (SwiftPM) package, which includes bundled prebuilt Qt binaries. Qt itself is listed as a dependecy of Qt Bridges, so SwiftPM will fetch it automatically.
There are two ways to add Qt Bridges to a project:
Add via Xcode
- In Xcode, select File -> Add Package Dependencies.
- Enter the Qt Bridges package URL.
- Xcode will automatically resolve and download Qt Bridges and its dependencies.
- Link the Qt Bridges product to the app target.
- Enable Swift-C++ interoperability:
- Go to the target's Build Settings.
- Switch the filter to All + Combined.
- Search for Interoperability.
- Under Swift Compiler - Language, set C++ and Objective-C Interoperability mode to C++/Objective-C++.
Add via Package.swift
- Specify the Qt Bridges package URL in the dependencies section.
- Link the Qt Bridges product to the app target.
- Enable Swift-C++ interoperability in swiftSettings with .interoperabilityMode(.Cxx) mode.
dependencies: [ .package(url: "<QtBridges-repo-url>", from: "") ], targets: [ .target( name: "MyApp", dependencies: [ .product(name: "QtBridges", package: "QtBridges") ], swiftSettings: [ .interoperabilityMode(.Cxx) ] ) ]
Setting up development environment
- Xcode / Swift toolchain: Swift 6.x with C++ interoperability enabled (Xcode 16+).
- Ensure Qt Bridges is linked to the app target.
Building the Qt Bridges package
From the Qt Bridges repository root, run
swift build -c debug
or
swift build -c release
SwiftPM will automatically fetch the binary Qt dependency declared by Qt Bridges.
Running
Example application that uses Qt Bridges can be run either from command line or directly in Xcode.
Command line
From the example root, run:
swift run
Xcode
- Open the repository folder in Xcode and select Package.swift
- Press the Run button
In both cases, SwiftPM will automatically fetch the Qt binary dependency declared by Qt Bridges on the first build.
Tutorials
Running the Example Minimal Application
The example app included with Qt Bridges is already set up with its own Package.swift. You can run it either directly in Xcode or from the command line.
Running via Xcode
- Locate the example project folder.
- Double-click on Package.swift — Xcode will open the project automatically.
- In Xcode, select the example app target.
- Press the Run button.
Running via Command Line
- Open Terminal and navigate to the example project root.
- Run:
swift run
- SwiftPM will build the project and launch the app.
In both cases, SwiftPM will automatically fetch and build the Qt binary dependency on the first run.
© 2025 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.