Qt 范例和教程

Qt 提供一批代码样本和教程,以帮助新用户入门 Qt 开发。这些文档涵盖一系列话题、从 Widget 的基本用法到分步教程,以展示如何把应用程序拼凑在一起。

范例是 Qt 包的一部分。请拜访 下载 页面,了解更多信息。

运行范例

打开和运行范例在 Qt Creator 欢迎 模式。大多数范例可在各平台上运行且可搜索特定平台范例,在搜索字段中键入平台名称 (或任何关键字)。例如,键入 Android 在搜索字段中列表完全兼容 Android 的范例。

有关在 Qt Creator 中运行范例的更多信息,拜访 构建和运行范例 页面。

要查看所有 Qt 范例的列表,请拜访 Qt 范例列表 页面。

应用程序范例

Calqlatr A Qt Quick app designed for portrait devices that uses custom components, animated with AnimationController, and JavaScript for the application logic.
咖啡机 具有基于状态的自定义用户界面的 Qt Quick 应用程序。
文档查看器 A Widgets application to display and print Json, text and PDF files. Demonstrates various features to use in widget applications: Using QSettings, query and save user preferences, manage file histories and control cursor behavior when hovering over widgets.
照片表面 A QML app for touch devices that uses a Repeater with a FolderListModel to access content in a folder, and a PinchHandler to handle pinch gestures on the fetched content.
食谱浏览器 Injecting custom stylsheets into web pages and providing a rich text preview tool for a custom markup language

连接

注解 URL (统一资源定位符) Example shows reading from formatted NFC Data Exchange Format (NDEF) messages
Blocking Receiver Shows how to use the synchronous API of QSerialPort in a non-GUI thread
Blocking Sender Shows how to use the synchronous API of QSerialPort in a worker thread
蓝牙聊天 Shows communication through Bluetooth using RFCOMM protocol
Bluetooth Low Energy Heart Rate Game A game demonstrating the interaction with a Bluetooth Low Energy Heart Rate device/service
Bluetooth Low Energy Heart Rate Server An example demonstrating how to set up and advertise a GATT service. The example demonstrates the use of the Qt Bluetooth Low Energy classes related to peripheral (slave) functionality
Bluetooth Low Energy Scanner An application designed to browse the content of Bluetooth Low Energy peripheral devices. The example demonstrates the use of all Qt Bluetooth Low Energy classes
CAN 总线管理器 Example sends and receives CAN bus frames
Modbus Client Example implements a Modbus client application
Modbus 自定义命令 Example shows how to handle custom Modbus function codes
Modbus 服务器 Example implements a Modbus server application
Serial Terminal Shows how to use various features of QSerialPort

桌面

计算器构建器 Creating a user interface from a Qt Designer form at run-time
计算器表单 在应用程序中使用采用 Qt Designer 创建的表单
计算器表单/多继承 在应用程序中使用采用 Qt Designer 创建的表单
容器扩展范例 Creating a custom multi-page plugin for Qt Designer
自定义 Widget 插件 Creating a custom widget plugin for Qt Designer
任务菜单扩展 Creating a custom widget plugin for Qt Designer and providing custom task menu entries that are associated with the plugin
文本查找器 Dynamically loading .ui files using QUiLoader

嵌入式

自定义 Shell Custom Shell shows how to implement a custom shell extension
IVI Compositor IVI Compositor is an example that demonstrates how to use the IviApplication extension
Minimal QML Minimal QML is a simple example that demonstrates how to write a Wayland compositor in QML
Multi Output Multi Output is an example that demonstrates a compositor with multiple outputs
Multi Screen Multi Screen is a desktop-style Wayland compositor for multiple screens
Overview Compositor Overview Compositor shows how to switch between clients in a grid
Pure QML Pure QML is an example that demonstrates how to write a Wayland compositor in pure QML
QtShell Compositor QtShell Compositor shows how to use the QtShell shell extension
Server Side Decoration Compositor Server Side Decoration Compositor is a simple example that demonstrates server side window decorations on xdg-shell
Spanning Screens Spanning Screens is an example that demonstrates how to let Wayland clients span multiple screens

图形

指针式时钟 Analog Clock example shows how to draw the contents of a custom widget
Axis Handling Implementing axis dragging with a custom input handler in QML, and creating a custom axis formatter
图形图库 Gallery of Bar, Scatter, and Surface graphs
Simple Bar Graph Using Bars3D in a QML application
Simple Scatter Graph Using Scatter3D in a QML application
Surface Graph Gallery Gallery with three different ways to use a Surface3D graph
体积渲染 Rendering volumetric objects
Wiggly Demonstrates how to use an effect created with the Qt Quick Effect Maker (QQEM)

输入/输出

Convert Example Convert example demonstrates how to convert between different serialization formats
DOM Bookmarks Application 提供用于 XML 书签交换语言文件的读取器
JSON 保存游戏范例 JSON Save Game example demonstrates how to save and load a small game using QJsonDocument, QJsonObject and QJsonArray
Parsing and displaying CBOR data A demonstration of how to parse files in CBOR format
QXmlStream 书签范例 演示如何读写 XBEL 文件

国际化

Arrow Pad 范例 理解 Qt Linguist 上下文概念和使用 2 种或多种语言
Hello tr() 范例 将小 Hello World 程序翻译成拉丁语
I18N 范例 演示 Qt 对翻译文本的支持
Troll Print 范例 更新用于稍后发行的翻译

移动

在 APP 中购买演示 演示购买 APP 中产品的完整移动应用程序。
Qt Android 通知程序 演示在 Android 应用程序中从 Qt 调用 Java 代码

网络

阻塞 Fortune 客户端 演示如何为网络服务创建客户端
聊天 在用户应用程序中使用 Qt GRPC 客户端 API
Fortune 客户端 演示如何为网络服务创建客户端
Fortune 服务器 演示如何为网络服务创建服务器
HTTP 客户端 演示简单 HTTP 客户端
Magic 8 Ball Creating a HTTP2 connection between a Qt GRPC client and a C++ gRPC server
多点播送接收器 演示如何接收发送给多点播送组的信息
多点播送发送器 演示如何把消息发送给多点播送组
QML WebSocket 客户端 Explains how to write a QML WebSocket client example
QML WebSocket 服务器 A simple example that shows how to use a QML WebSocketServer
Qt Quick Demo - RESTful Color Palette API client 如何创建 RESTful API QML 客户端的范例。
Qt WebSockets 范例 List of Qt WebSocket examples
SCXML FTP 客户端 使用状态机实现简单 FTP 客户端
安全 WebSocket 回显客户端 A simple client application using secure WebSockets (wss)
安全 WebSocket 回显服务器 A simple server to respond to clients over secure WebSockets (wss)
传感器 Sensors example shows how two applications can communicate by sending protobuf messages using UDP sockets
简单 WebSocket 聊天 A minimal chat application using the WebSocket protocol
线程化 Fortune 服务器 Threaded Fortune Server example shows how to create a server for a simple network service that uses threads to handle requests from different clients. It is intended to be run alongside the Fortune Client example
WebSocket 回显客户端 Show how to write a simple WebSocket client application
WebSocket 回显服务器 展示如何编写简单 WebSocket 服务器应用程序

位置 & 定位

Log File Position Source (C++) Logfile Position Source shows how to create and work with a custom position source. It can be useful for simulating GPS data, or when the data is received in some custom format
SatelliteInfo (QML) SatelliteInfo example shows the available satellites using Sky View or RSSI View and the user's current position. The satellites currently contributing to the GPS fix are marked as pink
Weather Info (C++/QML) Weather Info example shows how to use the user's current position to retrieve local content from a web service in a C++ plugin for QML

社区范例

要查看和运行由 Qt 工程提供的范例,拜访 社区范例 页面。

所有范例

所有 Qt 范例 列出了按其所属 Qt 模块分类的所有范例。